Lists, Tuples and Dictionaries Flashcards
what are lists?
collection of different types of elements within square brackets
list operators?
concatenation, repetition, membership
append()
adds new element to last in list
extend()
extends existing list to another list
insert()
Inserts element based on index number
pop()
removes element based on index number
reverse()
reverses a list
sort()
sorts list in ascending order ( Looking at starting alphabets)
sorted()
does the same thing as sort but wont change the list
min() and max()
gives maximum and minimum values in list
sum()
sum of elements in list
nested list?
list containing another list inside
What are tuples?
collection of different types of data within curved brackets they are immutable
packing and unpacking tuple means?
T= (1,2,3,4) → packed
a,b,c,d= (1,2,3,4)→unpacked
print(a) #1
what are dictionaries?
key:value pair withiin flower brackets
keys cant be similar but values can
keys()
Marks{“maths”:100, “physics”:100, “chemistry”:100}
print(Marks.keys())
prints all keys
values()
prints all values
items()
prints all items in dictionary
get()
gets specified value for key
update()
merges a dictionary with another
print(D1.update(D2))
puts D2 in D1
del()
deletes element with its key
clear()
removes everything if you print then you will get empty dictionary