Provide your own examples of the following using Python lists. Create your own examples. Do not copy them from another source.
Provide the Python code and output for your program and all your examples.
Nested lists
P = ['a1', ['a22', ['a33', 'a44'], 'a5', 'a6'], 'b', 'c']
List slices
P = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i']
print(P[2:7])
##Prints ['c', 'd', 'e', 'f', 'g']
The “+=” operator
C = [1, 2, 3]
Print (c) = [1, 2, 3]
c += c
c[1, 2, 3, 1, 2, 3]
A list filter
scores = [70, 60, 80, 90, 50]
filtered = filter(lambda score: score >= 70, scores)
print(list(filtered))
##prints([70, 80,
The “*” operator
list = [4, 5, 6, 3, 9]
K = 4
res = [x * K for x in list]
print ("The list after constant multiplication : " + str(res))
Comments
Leave a comment