(call bars,xyz lines, flats, )
Start List
List Basics
List overview:
List is one of the simplest and most important data structures in Python.
Lists are collections of ordered items called 'elements', they are enclosed in square brackets [ ] and separated by a comma ','
the items in a list are , they don't need to be the same data type, these items can even be a list itself!
Some examples of lists:
numbers = [1, 3, 5, 7] # list of numbers
eye_color = ['blue', 'brown', 'black'] # list of strings
empty_lst = []
lst = [[1,2], [3,4], [5,6]] # list of lists
Some ways to generate lists
Number list:
Other than just typing in a list, we can call list()
function on range()
function to generate a number list.
num_lst = list(range(5))
print(num_lst)
This way we get a number list showed in the console:
[0,1,2,3,4]
We can easily get a even number list this way:
even = list(range(2, 11, 2))
print(even) # result: [2,4,6,8,10]
Save your fingers from over typing if you need a list with a thousand numbers.
List 'operations' create new lists
'add' two list together, make two number lists and the third list is the addition of the first two. Build columns in 3 different color representing the 3 lists and compare them.
lst1 = [1,2,3]
lst2 = [6,7,8,9]
lst3 = lst1 + lst2
print(lst3) # [1,2,3,6,7,8,9]
'multiply' a list with a number
Make a number list, my_lst
, assign value my_lst * 3
to a new list result
.
my_lst = [1,8]
result = my_lst * 3
print( result ) # [1,8,1,8,1,8]