Session 4 - Arrays Flashcards
Arrays (21 cards)
String to Array (1min)
Input a List of Numbers separated by space and Print Them
Input: Enter numbers separated by space: 1 2 3 4 5
Output:
[1, 2, 3, 4, 5]
A
Array Sum (2mins)
Print the Sum of All Elements
Input: Enter numbers: 1 2 3 4
Output:
Sum = 10
A
Minimum/Maximum (2mins)
Find the Maximum and Minimum in a List
Input: Enter numbers: 3 7 1 9
Output:
Max: 9
Min: 1
A
Even/Odd Count (2mins)
Count Even and Odd Numbers
Input: Enter numbers: 1 2 3 4 5 6
Output:
Even: 3
Odd: 3
A
Reverse without reverse() (2mins)
Reverse a List Without Using reverse()
Input: Enter numbers: 10 20 30
Output:
[30, 20, 10]
A
Second Largest (2mins)
Find the Second Largest Number
Input: Enter numbers: 4 1 7 7 3
Output:
Second largest: 4
A
No Dupes (2mins)
Remove Duplicates From a List
Input: Enter numbers: 1 2 2 3 4 4 4 5
Output:
[1, 2, 3, 4, 5]
A
Beyond Average/Mean (3mins)
Find All Elements Greater Than Average
Input: Enter numbers: 10 20 30 40
Output:
Average: 25.0
Above average: [30, 40]
A
Cyclic Rotation (to the left) (3mins)
Rotate List Left by 1 Position
Input: Enter numbers: 1 2 3 4
Output:
[2, 3, 4, 1]
A
List Merge (2mins)
Merge Two Lists and Sort
Input:
Enter first list: 3 1
Enter second list: 5 2
Output:
[1, 2, 3, 5]
A
Join a List of Words into a Sentence (2mins)
Join words from a list into one space-separated string
Input: [“Python”, “is”, “awesome”]
Output:
Python is awesome
A
2x2 Matrix (3mins)
Input a 2×2 Matrix and Print It
Input: Enter 2 rows (space-separated):
1 2
3 4
Output:
[[1, 2], [3, 4]]
A
3x3 matrix sum (3mins)
Sum of All Elements in a 3×3 Matrix
Input: Enter 3 rows:
1 2 3
4 5 6
7 8 9
Output:
Sum = 45
A
Transpose (3mins)
Transpose of a 3×3 Matrix
Input:
1 2 3
4 5 6
7 8 9
Output:
[1, 4, 7]
[2, 5, 8]
[3, 6, 9]
A
2x2 Add (3mins)
Add Two 2×2 Matrices
Matrix A:
1 2
3 4
Matrix B:
5 6
7 8
Output:
[6, 8]
[10, 12]
A
Diagonal (3mins)
Print Diagonal Elements of a 3×3 Matrix
Input:
1 2 3
4 5 6
7 8 9
Output:
Primary Diagonal: [1, 5, 9]
Secondary Diagonal: [3, 5, 7]
A
Max element (3mins)
Find Max Element in Each Row
Input:
3 1 4
2 5 9
8 7 6
Output:
[4, 9, 8]
A
2x2 Matrix (3mins)
Input a 2×2 Matrix and Print It
Input:
Enter 2 rows (space-separated):
1 2
3 4
Output:
[[1, 2], [3, 4]]
A
3x3 matrix sum (3mins)
Sum of All Elements in a 3×3 Matrix
Input:
Enter 3 rows:
1 2 3
4 5 6
7 8 9
Output:
Sum = 45
A
3x3 matrix 1 row matrix (3mins)
Flatten a 2D Matrix to 1D List
Input:
Enter 3 rows:
1 3 2
4 5 6
7 8 9
Output:
[1, 3, 2, 4, 5, 6, 7, 8, 9]
A
3x3 matrix sum (3mins)
Sum of All Elements in a 3×3 Matrix
Input:
Enter 3 rows:
1 2 3
4 5 6
7 8 9
Output:
Sum = 45
A