Answer to Question #193088 in Python for FORTUNE AIDOO

Question #193088

Part 2

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
2021-05-15T13:47:29-0400
# Nested lists
nested_list = ['a', 'b', ['c', 'd', ['11', '55']], 'h', 'l','u','z']
print("nested_list: ")
print(nested_list)
# The "*" operator
petNames=["Charlie","Max","Buddy"]*2
print("The \"*\" operator: ")
print(petNames)
# List slices
print("List petNames slices: ")
print(petNames[1:3])
# The "+=" operator
print("The \"+=\" operator: ")
petNames+=["Tod","Tommy"]
print(petNames)
# A list filter
print("A list filter")
filteredPetNamesList = filter(lambda name: name !="Tod", petNames)
print(list(filteredPetNamesList))
# A list operation that is legal but does the "wrong" thing, not
# what the programmer expects
# I wanted to sort the "petNames" List, but the result is None
print("Sort the \"petNames\" List")
petNames = petNames.sort()
print(petNames)


Example:



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