party \= ["ice cream","sprinkles","nuts"] party.pop() print(party)
\["ice cream","sprinkles",]
19
New cards
Remove "ice cream" using "delete"
party \= ["ice cream","sprinkles","nuts"]
party.delete[0]
20
New cards
what will the following lines do
party \= ["ice cream","sprinkles","nuts"] del party print(party)
Error \[Deletes list]
21
New cards
what will the following lines do
party \= ["ice cream","sprinkles","nuts"] party.clear() print(party)
\[BLANK] \[Deletes items in list, not list itself]
22
New cards
loop the items in the list fruits \= ["grapefruit","pineapple","kumquat"]
for x in fruits: print(x)
23
New cards
loop the items in the list by its length fruits \= ["grapefruit","pineapple","kumquat"]
for x in range(len(x)): print(fruits[x])
24
New cards
loop the items in the list using its length fruits \= ["grapefruit","pineapple","kumquat"]
x \= 0 while x < len(fruits): print (fruits [x]) x +\= 1
25
New cards
loop the items in the list with a single line
\[print(x) for x in fruits]
26
New cards
for the list "languages" add all asian languages to the following list languages \= ["japanese","chinese","german","french"] translator \= ?
translator \= [x for x in languages if "ese" in x]
27
New cards
for the list "ores" add all items EXCLUDING "diamond" using the if condition ores \= ["iron", "gold", "diamond", "lapis", "emerald"] inventory \= ?
inventory \= [x for x in ores if x !\= "diamond"]
28
New cards
what is the syntax for list comprehension
newlist \= [ expression for item in iterable if condition \== True]
29
New cards
what will happen in the following list comprehension inventory \= ["D", "C", "B", "A" , "S"] myinventory \= [x for x in inventory]
inventory duplicates into myinventory myinventory \= ["D", "C", "B", "A" , "S"]
30
New cards
iterable
an object capable of returning its members one at a time.
31
New cards
return all the items in the list lowercased mylist \= ["HAPPY", "sad", "Inspired"]
mylist_1 \= [x.lower() for x in mylist]
32
New cards
return all items in the list as "null" mylist \= ["player_data", "saves", "memory"]
mylist_1 \= ["null" for x in mylist]
33
New cards
return all items in the list except those containing less than 5 characters to which replace them with "INCREASE_LENGTH" mylist \= ["superfluous", "goad", "schadenfreude", "ubiquitous", "din"]
mylist_1 \= [x if len(x)\> 5 else "INCREASE_LENGTH" for x in mylist]
34
New cards
Arrange the list alphabetically in ascending order mylist \= ["apple", "orange", "grapefruit", "peach"]
mylist.sort()
35
New cards
Arrange the list alphabetically in descending order mylist \= ["apple", "orange", "grapefruit", "peach"]
mylist.sort(reverse \= True)
36
New cards
Arrange the list by character count in ascending order mylist \= ["chocolate", "Brazil", "dance"]
def mykey(x): return len(x)
mylist.sort(key \= mykey)
37
New cards
What kind of strings are sorted first
Capitalized strings
38
New cards
sort the list alphabetically in ascending order regardless of capitalization mylist \= ["apple", "orange", "grapefruit", "peach"]
mylist.sort(key \= str.lower())
39
New cards
arrange the list backwards, disregarding alphabetization mylist \= ["apple", "orange", "grapefruit", "peach"]
mylist.reverse()
40
New cards
add the string "midnights" to the end of the list ts \= ["lover", "folklore", "evermore"]
ts.append("midnights")
41
New cards
add the string "1989" as the 2nd item ts \= ["speak_now","red","reputation"]
ts.insert(1, "1989")
42
New cards
append the items from the former list to the latter new \= ["btc", "lh"] existing \= ["lush", "rfascib", "bmamc", "puberty_2"]
existing.extend(new)
43
New cards
what are the issues with list_1 \= list_2 when copying lists
changes to one list will affect the other
44
New cards
copy the list from the former list to the latter movie \= ["appreciative","nature_lover","romantic"] personality \= ?
personality \= list(movie) OR personality \= movie.copy()
45
New cards
join two list even_numbers \= [0, 2, 4] odd_numbers \= [1, 3, 5]
all_numbers \= even_numbers + odd_numbers OR even_numbers.extend(odd_numbers)
46
New cards
join two list by appending each item individually from the former list to the latter even_numbers \= [0, 2, 4] odd_numbers \= [1, 3, 5]