Mind map
Lists, Tuples, Sets and Dictionaries
Map content
Lists, Tuples, Sets and Dictionaries
myList = ["lemon", "banana", True, "lemon", 4, 15]
- ordered
- changeable
- allow duplicates
- changeable
- to append element to end of existing list:
- myList.append("apple")
- to remove element from list:
- myList.remove("lemon")
- only removes FIRST instance of "lemon"
- myList.pop(3)
- removes element at index 3
- myList.remove("lemon")
- to access specific element in list:
- item = myList[4]
- ordered
myTuple = ("mouse", 33, True, 1888, "guru")
- ordered
- unchangeable
- allow duplicattes
- unchangeable
- anotherTuple = ("Captain Jack Sparrow",)
- item = myTuple[1]
- lastItem = myTuple[-1]
- subtuples
- print(myTuple[1, 3])
- ordered
mySet = {"lemon", "banana", True, 4, 15}
- unordered
- unchangeable
- reject duplicates
- unchangeable
- to check if element exists in set:
- print("apple" in mySet)
- FALSE
- print("banana" in mySet)
- TRUE
- to add element to set:
- mySet.add("orange")
- print("apple" in mySet)
- newSet = {"face", "elbow", 32}
- mySet.update(newSet)
- print(mySet)
- mySet.update(newSet)
- unordered
houseForRent = {"style": "American Craftsman", "bedrooms": 3, "bathrooms": 2, "rent": 2500, "available": True}
- key : value
- to add new key:value
- houseForRent["color": "white"
- to add new key:value
- key : value
Information
- Description
- Mind Map on Lists, Tuples, Sets and Dictionaries, created by Benjamin Brandt on 03/02/2021.
- Created by
- Benjamin Brandt
- Views
- 0
- Rating