Answer to Question #307574 in Python for dode

Question #307574

Provide your own examples of the following using Python lists. Create your own examples. Do not copy them from another source. 

  • Nested lists 
  • The “*” operator 
  • List slices 
  • The “+=” operator 
  • A list filter 
  • A list operation that is legal but does the "wrong" thing, not what the programmer expects 

Provide the Python code and output for your program and all your examples. 


1
Expert's answer
2022-03-08T07:11:44-0500
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))








Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS