Untitled
unknown
plain_text
a year ago
1.6 kB
13
Indexable
Never
# Nested Lists food = [['apple', 'banana', 'grapes'], ['avocado', 'onion', 'carrot'], ['pie', 'mac&cheese', 'pasta']] print(food) # The “*” operator book_titles = "Emma Night Lolita Dracula Rebecca Hamlet Utopia".split() print(book_titles) # ['Emma', 'Night', 'Lolita', 'Dracula', 'Rebecca', 'Hamlet', 'Utopia'] print(*book_titles) # Emma Night Lolita Dracula Rebecca Hamlet Utopia numbers = [1, 2, 3, 4] print(numbers*2) # [1, 2, 3, 4, 1, 2, 3, 4] # List Slices book_titles = "Emma Night Lolita Dracula Rebecca Hamlet Utopia".split() print(book_titles[2:4]) # ['Lolita', 'Dracula'] print(book_titles[2:]) # ['Lolita', 'Dracula', 'Rebecca', 'Hamlet', 'Utopia'] print(book_titles[:5]) # ['Emma', 'Night', 'Lolita', 'Dracula', 'Rebecca'] print(book_titles[:]) # ['Emma', 'Night', 'Lolita', 'Dracula', 'Rebecca', 'Hamlet', 'Utopia'] # The += operator book_titles = "Emma Night Lolita Dracula".split() print(book_titles) book_titles += ['Rebecca', 'Hamlet', 'Utopia'] # book_titles = book_titles + ['Rebecca', 'Hamlet', 'Utopia'] print(book_titles) # Filter List book_titles = "Emma Night Lolita Dracula Rebecca Hamlet Utopia".split() print(book_titles) filtered_books = list(filter(lambda book_title: len(book_title)>5, book_titles)) print(filtered_books) # f) A list operation that is legal but does the "wrong" thing, and not what the programmer expects book_titles = "Emma Night Lolita Dracula".split() book_titles = book_titles.append('Hamplet') print(book_titles)