working with lists & Tuples Flashcards
Question: What will be the result of this slicing operation of the names_list?
Code Editor:
names_list = [‘John’, ‘James’, ‘Lily’, ‘Emily’, ‘Nina’]
names_list[::2]
[‘John’, ‘Lily’, ‘Nina’]
Which of the following lines of code will print this string in reverse i.e. print out “olleH”
some_str[::-1]
some_list = [‘a’, ‘b’, ‘c’, ‘d’, ‘e’, ‘f’]
How do you slice this list to access the elements ‘c’, ‘d’?
some_list[2:4]
If you want to count the number of times the name “John” appears in the names_list what function would you invoke?
names_list.count(“John”)
Question: What is the result of executing this code?
Code Editor:
some_string = “Python”
a, b, c, d = some_string
This is an error, “too many values to unpack”
Question: If you wanted to insert an element at index 2 in a particular list named names_list what is the function that you would invoke?
names_list.insert(2, “John”)
Question: If you wanted to sort the elements in the list names_list in alphabetical order which of the following statements in Python are valid?
names_list.alphabetical_sort()
names_list = sorted(names_list)
names_list = sort_alpha(names_list)
names_list.sort()
names_list = sorted(names_list)
names_list.sort()
Question: What is the result of executing this code?
Code Editor:
city = ‘Los Angeles’
city.find(‘x’)
-1
Question: Which of the following are valid complex data types in Python?
Sets, lists, dictionaries