forked from bnsreenu/python_for_image_processing_APEER
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tutorial13_tuples.py
46 lines (30 loc) · 1022 Bytes
/
tutorial13_tuples.py
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
41
42
43
44
45
46
#Video Playlist: https://www.youtube.com/playlist?list=PLHae9ggVvqPgyRQQOtENr6hK0m1UquGaG
"""
Tuple is a list that is immutable - cannotbe modified
"""
a = (1,2,3,4,5) #Set of numbers
b = (2, 4, 'apple', 'banana') #Numbers and/or text
#Can convert tuple to list and vice versa
b2 = list(b)
print(type(b2))
print(b[2]) #3rd element in the list
b.append('grape') #add to the list. Lists are editable
print(b)
d = tuple(range(20)) #Generate a list using range
print(d)
e = d[3:7] #Subset of d from 4th to 7th element. Creates new tuple
print(e)
f = d[11:] #Subset from 12th element to end of the list
print(f)
g = d[:5] #Subset upto 5th element
print(g)
h = a+b #Add tuples, concatenate
print(h)
print(len(h)) #tells the length of the list
print(max(d))
#Multidimensional lists
x = [(1,2), (3,4)]
print(2*x)
#Multiplying every element by 2 is not easy with lists.
#Just repeats the list that many times.
#This is where we can rely on the strength of numpy.