Data_structures_in_python
Data_structures_in_python
• nums.append([6,7,8]) • nums.extend([6,7,8])
• a[start:end]
– # items start through end-1
• a[start:]
– # items start through the rest of the array
• a[:end]
– # items from the beginning through end-1
• a[:]
– # a copy of the whole array
• a[start:end:step]
– # start through not past end, by step
• For Loops
• While loop
listOfWords = ["this","is","a","list","of","words"]
items = [ word[0] for word in listOfWords]
print (items)
Output: ['t', 'i', 'a', 'l', 'o', 'w']
A={1,2,3,4}
Key Value
Key Value
• More than one entry per key not allowed. Which means no
duplicate key is allowed. When duplicate keys encountered
during assignment, the last assignment wins.
• dict.items()
– Returns a list of dict's (key, value) tuple pairs.
• dict.keys()
– Returns list of dictionary dict's keys
• dict.values()
– Returns list of dictionary dict's values
• dict.update(dict2)
– Adds dictionary dict2's key-values pairs to dict