Lists Flashcards
What a list in Python is?
datatype you can use to store a collection of different pieces of information as a sequence under a single variable name.
How you can assing items to a list? How you can create lists? Give an example of expression
list_name = [item_1, item_2]
How to create an empty list?
empty = []
How you can access the particular item inside the list
list_name[0] #it is called index
How to replace an item inside the list with another. Replace the first item inside the list list=[‘one’,’two’]
list[0]=’the real one’
How to add items to a list
list_name.append(“I have new friends”)
What is list slicing? How it is performed in Python? On how many ways it can be called ?
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 can you slice strings and lists
animal{:3] #from begining to 3rd ithem(WITH) animal[1:] #from first to last
What is called the function that can search throught the list and returns an index of this item?
list.index(“The item value”)
How looks the function that adds an item at specified index
list.insert(1, “dog”) #inserts dog at index one
How to iterate through all items inside the list
for thing in list: print thing #prints all things inside the list
How to sort items inside the list
list.sort()
How to use keys inside the list -> create hash maps
d = {‘key1’ : 1, ‘key2’ : 2, ‘key3’ : 3}
How to add new entries into the Python Key list -> hash map
list[‘new key’] = ‘new crazy value’
How can you get rid of a specific value inside the dictionary. DIctionaries are mutable.
del dict_name[key_name] # will remove the item with specific key