Lists Flashcards
A list
used to store multiple items in a single variable
2d lists
A list of lists
List example
Name of list: Food
Items in list: pie,cream and waffles
Food = [“pie”, “cream”, “waffles”]
Finding the first index of “Food”
Food = [“pie”, “cream”, “waffles”]
Food[0]
2D list example
The 2D list “Food” made up of variables such as breakfast,lunch,dinner
Food = [breakfast,Lunch,Dinner]
Finding the second index of the second list in a 2D list:
List_name[1][1]
Tuple
Collection which is ordered and h changeable
-used to group together related data
Is a bracket or square bracket used in a tuple?
() bracket
Example of tuple:
This tuple is called creator
And contains Alex,15 and male
Creator = (“Alex”,15,”male”)
sets
A collection which is unordered,unindexed and has no duplicate values
(Uses {} curly brackets)
Set example:
Set is called children and contains Billy,Timothy and Johnathan
Children = {“Billy”,”Timothy”,”Johnathan”}
Dictionary
A changeable, unordered collection of unique key: value pairs
-a fast because they use hashing meaning values can be accessed quickly
Dictionary example:
Name of dictionary is Animals
Contains the keys:Reptiles,birds,amphibians
Animals = {‘reptiles’: ‘lizard’, ‘birds’: ‘parrots’ , ‘amphibians’: ‘frog’}
“Items” in a dictionary
Refers to the key and value in dictionaries