Repository navigation
Expand file tree
/
Copy pathList.py
More file actions
41 lines (29 loc) · 2.32 KB
/
Copy pathList.py
File metadata and controls
41 lines (29 loc) · 2.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# list of data in a single variable
# fruits = ["apple", "banana"]
# print(fruits)
states_of_america = ["Delaware", "Pennsylvania", "New Jersey", "Georgia", "Connecticut", "Massachusetts", "Maryland", "South Carolina", "New Hampshire", "Virginia", "New York", "North Carolina", "Rhode Island", "Vermont", "Kentucky", "Tennessee", "Ohio", "Louisiana", "Indiana", "Mississippi", "Illinois", "Alabama", "Maine", "Missouri", "Arkansas", "Michigan", "Florida", "Texas", "Iowa", "Wisconsin", "California", "Minnesota", "Oregon", "Kansas", "West Virginia", "Nevada", "Nebraska", "Colorado", "North Dakota", "South Dakota", "Montana", "Washington", "Idaho", "Wyoming", "Utah", "Oklahoma", "New Mexico", "Arizona", "Alaska", "Hawaii"]
print(states_of_america[2])
print(states_of_america[-2])
# -2 in the above means the list index from backwards do note that from backwards the index starts from -1 and not 0
# Inside a list the order of the data is maintained by an index which can be as follows [0, 1, 2, 3, 4, 5]
# if the list is ["Delaware", "Pennsylvania", "New Jersey", "Georgia", "Connecticut", "Massachusetts"] then the referring index to the following would be [0, 1, 2, 3, 4, 5]
# altering the list
# states_of_america[1] = "Penisvania"
# print(states_of_america)
# Add an item to the end of the list
# states_of_america.append("FuckOffLand") add one record
# states_of_america.extend(["FuckOffLand", "MilfLand"]) add more than one record but need to put [] before adding as it signifies list structure
print(states_of_america)
# https://docs.python.org/3/tutorial/datastructures.html => Data structure
# in order to print the correct number inside a list
num = len(states_of_america)
# print(states_of_america[num]) => error IndexError: list index out of range
print(states_of_america[num - 1])
dirty_dozen = ["Strawberries", "Spinach", "Kale", "Nectarines", "Apples", "Grapes", "Peaches", "Cherries", "Pears", "Tomatoes", "Celery", "Potatoes"]
# list within a list is called nested list
fruits = ["Strawberries", "Nectarines", "Apples", "Grapes", "Peaches", "Cherries", "Pears"]
vegetables = ["Spinach", "Kale", "Tomatoes", "Celery", "Potatoes"]
dirty_dozen = [fruits, vegetables]
print(dirty_dozen[0])
print(dirty_dozen[1])
# print(dirty_dozen[1][1]) this gives [1] from fruits, veegetables which is vegetables and another [1] inside the list vegetable kale