Python: Lists Flashcards
Which of the following is the correct way to turn the following into a list of names: “Tom”, “Jerry”, “Tweetie”, “Sylvester”?
names = [“Tom”, “Jerry”, “Tweetie”, “Sylvester”]
names = “Tom”, “Jerry”, “Tweetie”, “Sylvester”
names = [“Tom” “Jerry” “Tweetie” “Sylvester”]
names = {“Tom”, “Jerry”, ‘Tweetie”, “Sylvester”}
names = [“Tom”, “Jerry”, “Tweetie”, “Sylvester”]
Which of the following is the correct way to remove the first instance of “Rio” from name_list?
name_list.remove([Rio])
remove(name_list[“Rio”])
“Rio”.remove(name_list)
name_list.remove(“Rio”)
name_list.remove(“Rio”)
Is the following list a valid Python list?
mylist = [“Mount Everest”, 29029]
Yes, lists can contain multiple data types.
Which of the following is the correct way to create an empty list?
empty_list = []
empty_list = [0]
empty_list = {}
empty_list = None
empty_list = []
What would be the proper way to access “Strawberry” from the list groceries
groceries = [“Grapes”, “Strawberry”, “Starfruit”, “Apple”]
groceries[1]
The Python method .remove() will delete every instance of a provided value.
False
👏
Correct! The .remove() method removes only the first matching element in a list.
Which of the following is the correct way to add the number 4 to number_list?
number_list.append([4])
number_list.append(4)
4.append(number_list)
number_list + 4
number_list.append(4)
How would you access “77.45” from the following list?
student_data = [[“Ali”, 90], [“Bob”, 87.5], [“Cam”, 80.3], [“Doug”, 77.45]]
student_data[-1][-1]
Which of the following lines of code will correctly sort mylist?
mylist.sorted()
sort(mylist)
mylist.sort
mylist.sort()
mylist.sort()
Which of the following lines of code would slice the list [“b”, “c”] from mylist:
mylist = [“a”, “b”, “c”, “d”, “e”]
mylist[1:3]
Which list would be created by running this code?
list(range(2, 14, 4))
[2, 6, 10]
What would create a range object that starts at 3 and goes up to 15 (non-inclusive) in increments of 4?
range(3, 15, 4)
Which of the following lines of code will tell us how many times “win” appears in the list game_results?
count(game_results, “win”)
“win”.count(game_results)
game_results.count(“win”)
game_results.count(“win”)
What would be generated by the code snippet?
mylist = [“a”, “b”, “c”, “d”, “e”, “f”]
print(mylist[2:5])
[“c”, “d”, “e”]
What will return the length of the list mylist?
len(mylist)