Corisco Strings Lists Tuples and Dictionaries in Python - BW
Corisco Strings Lists Tuples and Dictionaries in Python - BW
Strings string = "words" or 'words' maxsplit is optional, all occurrences is default(-1) string.split("-
conect string1+string2 ",1)
enumerate(index, value) for i, v in enumerate(list): /n "{i} : {v}' Dictionaries dict = {"key":"value", "key2":"value2"}
for loop for x in list: ordered, changeable, do dict={"key1": bool,"key2":int, "key3":
through index for x in range(len(list)): not allow duplicates [list]}
while loop while x <= len(list): /n i+=1 dict cannot have same keys
Tuples tuple = ("value1", int, bool ,"value1") dict.get("key","return if value4 = dict.get("key4", "Not found")
not found")
are unordered, unchan‐ tuple = (item1,)
geable, allow duplicates List of Keys x = dict.keys()
Access [start index tuple[1] / tuple[-1], tuple[2:5], tuple[:5] if values exists if "value1" in dict.values()
included:end index not] Change values of a key dict["key"] = value
Check if Item exists if "item" in tuple: using update() dict.update({'key':'value'})
Change items tuples are list = list(tuple) Add dict["key"] = value
unchangeable
also can use update() dict.update({'key':'value'})
convert tuple to list and tuple = tuple(list)
Remove .pop or popite‐ dict.pop("key") / dict.popitem()
back to tuple
m(removes the last key
Concatenate add tuple to tuple1 + tuple2 / tuple1 =+ tuple2 inserted))
a tuple
using del del dict("key")
Lists inside a tuple are tuple = (["value1","value2"], item2,
del can delete the del dict
changeable item3)
dictionary completely
count() returns the tuple.count() / tuple.count('value')
clear empties the dict.clear() or dict = {}
number of items
dictionary
index() finds the item and tuple.index('value')
Copy dict = dict2 / dict2 = dict.copy() / dict2 =
return its index
dict(dict)
min() / max() / sum() tuple.min() tuple.max() tuple.sum()
items() dict.items()
enumerate(index, value) for i, v in enumerate(tuple): /n "{i} : {v}'
keys() dict.keys()
for loop for x in tuple:
values() dict.values()
through index for x in range(len(tuple)):
for loop for keys in dict:
while loop while x <= len(tuple): /n i+=1
keys for keys in dict.keys():
list compreehension [print[x] for x in tuple]
values for values in dict.values():
keys and values for keys, values in dict.items()