Learn practical skills, build real-world projects, and advance your career
Created 4 years ago
Question 1:
Given a Python list you should be able to display Python list in the following order
aLsit = [100, 200, 300, 400, 500]
Expected output:
[500, 400, 300, 200, 100]
aLsit = [100, 200, 300, 400, 500]
bList = aLsit[::-1]
bList
[500, 400, 300, 200, 100]
Question 2:
Concatenate two lists index-wise
list1 = ["M", "na", "i", "Ke"]
list2 = ["y", "me", "s", "lly"]
Expected output:
['My', 'name', 'is', 'Kelly']
list1 = ["M", "na", "i", "Ke"]
list2 = ["y", "me", "s", "lly"]
list3 = [i + j for i, j in zip(list1, list2)]
print(list3)
['My', 'name', 'is', 'Kelly']
# zip function explained
nums = [1,3,4]
char = ['a','s','f']
zipped = zip(nums,char)
print(list(zipped))
[(1, 'a'), (3, 's'), (4, 'f')]