2d Array
2d Array
array=[[23,45,43,23,45],[45,67,54,32,45],[89,90,87,65,44],[23,45,67,32,10]]
#display
print(array)
Accessing the values
Traversing Elements in 2D list using For loop
Inserting the values into the 2D array
Example
Updating the values into the 2D array
Example
Deleting the values from 2D array
Example
Get the size of 2D array
You can get the size of the two-dimensional array using the len() function. It will return the
number of rows in the array
Example
Programming Exercises
1.Two Sum
Description: Given an array of integers, return indices of the two numbers such that they add
up to a specific target.
Problem Link: Two Sum
3. Rotate Array
Description: Rotate an array to the right by a given number of steps.
Problem Link: Rotate Array
Programming Exercises
4. Contains Duplicate
Description: Given an array of integers, determine if the array contains any duplicates. Problem
Link: Contains Duplicate
5. Single Number
Description: Given a non-empty array of integers, every element appears twice except for one. Find
that single one.
Problem Link: Single Number
8. Move Zeroes
Description: Given an array, move all the zeroes to the end while maintaining the relative order of the
other elements.
Problem Link: Move Zeroes
9. Pascal's Triangle
Description: Given a non-negative integer numRows, generate the first numRows of Pascal's triangle.
Problem Link: Pascal's Triangle
For example,
• Indexing: One way is to treat strings as a list and use index values. For example,
• Negative Indexing: Similar to a list, Python allows negative indexing for its strings. For
example,
Access String Characters in Python
Slicing: Access a range of characters in a string by using the slicing operator colon :
For example,
Python Strings are immutable
In Python, strings are immutable. That means the characters of a string cannot be changed.
For example,
For example,
Python String Operations
There are many operations that can be performed with strings which makes it one of the most
used data types in Python.
For example,
Python String Operations
2. Join Two or More Strings(concatenation)
In Python, we can join (concatenate) two or more strings using the + operator.
For example,
In the above example, we have used the + operator to join two strings: greet and name.
Iterate Through a Python String
• We can iterate through a string using a for loop.
• For example,
Python String Length
• In Python, we use the len() method to find the length of a string.
For example,
String Membership Test
• We can test if a substring exists within a string or not, using the keyword in
Methods of Python String
Methods Description
For example,
This new formatting syntax is powerful and easy to use. From now on, we will use f-Strings
to print strings and variables.
Programming Exercises
1. Valid Palindrome
Description :-Given a string, determine if it is a palindrome, considering only
alphanumeric characters and ignoring cases.
Problem Link: Valid Palindrome
2. Reverse String
Description:-Write a function that reverses a string. The input string is given as an array
of characters.
Problem Link: Reverse String
3. Longest Substring
Description :-Without Repeating Characters Given a string, find the length of the longest
substring without repeating characters.
Problem Link: Longest Substring Without Repeating Characters
Programming Exercises
4. Implement strStr()
Description: Implement the strStr() function to find the first occurrence of a substring in a string. If the
substring is not found, return -1.
Problem Link: Implement strStr()
5. Group Anagrams
Description: Given an array of strings, group anagrams together.
Problem Link: Group Anagrams
6. Valid Parentheses
Description: Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input
string is valid.
Problem Link: Valid Parentheses
Programming Exercises
7. String to Integer (atoi)
Description: Implement the atoi() function which converts a string to an integer. Problem Link:
String to Integer (atoi)