Lists Flashcards

1
Q

What a list in Python is?

A

datatype you can use to store a collection of different pieces of information as a sequence under a single variable name.

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

How you can assing items to a list? How you can create lists? Give an example of expression

A

list_name = [item_1, item_2]

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

How to create an empty list?

A

empty = []

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

How you can access the particular item inside the list

A

list_name[0] #it is called index

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

How to replace an item inside the list with another. Replace the first item inside the list list=[‘one’,’two’]

A

list[0]=’the real one’

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

How to add items to a list

A

list_name.append(“I have new friends”)

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

What is list slicing? How it is performed in Python? On how many ways it can be called ?

A
first  = suitcase[0:2]  
# The first and second items (index zero and one)
middle = suitcase[2:4]         
# Third and fourth items (index two and three)
last   = suitcase[4:]           
 # The last two items (index four and five)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How can you slice strings and lists

A
animal{:3] 
#from begining to 3rd ithem(WITH)
animal[1:] #from first to last
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is called the function that can search throught the list and returns an index of this item?

A

list.index(“The item value”)

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

How looks the function that adds an item at specified index

A

list.insert(1, “dog”) #inserts dog at index one

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

How to iterate through all items inside the list

A
for thing in list:
    print thing 
#prints all things inside the list
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How to sort items inside the list

A

list.sort()

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

How to use keys inside the list -> create hash maps

A

d = {‘key1’ : 1, ‘key2’ : 2, ‘key3’ : 3}

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

How to add new entries into the Python Key list -> hash map

A

list[‘new key’] = ‘new crazy value’

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

How can you get rid of a specific value inside the dictionary. DIctionaries are mutable.

A
del dict_name[key_name]
# will remove the item with specific key
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

To remove something from a list you need to use?

A

list.remove(“matching pattern”)

17
Q

Can you join dictionaries and lists together?

A
my_dict = {
    "fish": ["c", "a", "r", "p"],
    "cash": -4483,
    "luck": "good"
}
print my_dict["fish"][0]