1. Take two input strings and print out every odd indexed character of first string and then
followed by even indexed characters of the second string.
Input
-----
string1 <--- "abcdefghi"
string2 <--- "jklmnopqr"
Output
------
bdfhjlnpr
2. Take two input strings and construct a new string using list comprehension and join operation.
The new string should be constructed such that if character at index `i` is uppercase for string1
then choose it, if not then choose character at index `i` of string2. Whatever character you put in
should be an uppercase character so make sure you coerce it to one.
Assume that both input strings are of equal length.
Use Google to find out what you don't know. Remember we won't be spoonfeeding....and even
if we want to, it's near impossible to do it.
Input
-----
string1 <--- "ABCDEF"
string2 <--- "jKlmno"
string1 <--- "abcdef"
string2 <--- "jklmno"
string1 <--- "AbCDEfghI"
string2 <--- "jKlmnoPQR"
Output
------
ABCDEF
JKLMNO
AKCDEOPQI
3. Accept four numbers as input namely -> length, breadth, height of a cube and N. The output should
be a dictionary of vertices whose manhattan distance from (0, 0, 0) is less than N.
Do this using comprehension/generator expression.
Example of dict comprehension
-----------------------------
words = ["one", "two", "three"]
dict = {i + 1 : word for i, word in enumerate(words)}
dict = {(x, y, z) : man...distance for i........... if man....}
Input
-----
Enter length : 5
Enter breadth : 5
Enter height : 5
Enter N : 10
Enter length : 2
Enter breadth : 5
Enter height : 3
Enter N : 7
Output
------
{(0, 0, 5): 5, (0, 0, 0): 0, (5, 0, 0): 5, (0, 5, 0): 5}
{(0, 0, 0): 0, (2, 0, 3): 5, (0, 5, 0): 5, (0, 0, 3): 3, (2, 0, 0): 2}
4. Print out the spiral traversal of a given matrix. You don't need to take it as input.
Just set it directly in the code. Assume it's a square matrix with odd number of rows/columns.
Remember Python doesn't have matrix natively so assume as list of lists for now.
Note : To get number of rows : len(matrix_name)
To get number of columns : len(matrix_name[0])
Test cases
----------
a = [[1]]
b = [[1, 2, 3],
[4, 5, 6],
[7, 8, 9]]
c = [[1, 2, 3, 4, 5],
[6, 7, 8, 9, 10],
[11, 12, 13, 14, 15],
[16, 17, 18, 19, 20],
[21, 22, 23, 24, 25]]
Output
------
a --> 1,
b --> 1, 2, 3, 6, 9, 8, 7, 4, 5,
c --> 1, 2, 3, 4, 5, 10, 15, 20, 25, 24, 23, 22, 21, 16, 11, 6, 7, 8, 9, 14, 19, 18, 17, 12, 13,