working with lists & Tuples Flashcards

1
Q

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]

A

[‘John’, ‘Lily’, ‘Nina’]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Which of the following lines of code will print this string in reverse i.e. print out “olleH”

A

some_str[::-1]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

some_list = [‘a’, ‘b’, ‘c’, ‘d’, ‘e’, ‘f’]
How do you slice this list to access the elements ‘c’, ‘d’?

A

some_list[2:4]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

If you want to count the number of times the name “John” appears in the names_list what function would you invoke?

A

names_list.count(“John”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Question: What is the result of executing this code?

Code Editor:
some_string = “Python”
a, b, c, d = some_string

A

This is an error, “too many values to unpack”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

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?

A

names_list.insert(2, “John”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

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()

A

names_list = sorted(names_list)
names_list.sort()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Question: What is the result of executing this code?

Code Editor:
city = ‘Los Angeles’
city.find(‘x’)

A

-1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Question: Which of the following are valid complex data types in Python?

A

Sets, lists, dictionaries

How well did you know this?
1
Not at all
2
3
4
5
Perfectly