-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path06_lists.py
More file actions
60 lines (42 loc) · 991 Bytes
/
06_lists.py
File metadata and controls
60 lines (42 loc) · 991 Bytes
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env python
#### tuple
staticList = (23, 42, 'bar')
print staticList
## better not show? could be confusing
# pack vars to list
#staticList = 23, 42, 'bar'
#print staticList
# extract list to vars
#a1, a2, a3 = staticList
#print a3
# access single item by index
print staticList[1]
### list
aList = [3, 2, 4, 1, 'hamster', 'foo']
print aList
# access single item by index
print aList[3]
aList.reverse()
print aList
#sorted(aList)
aList.sort()
print aList
aList.append('bar')
print aList
tmpFoo = aList.pop()
print 'tmpFoo:', tmpFoo, 'aList:', aList
tmpFoo = aList.pop(-1)
print 'tmpFoo:', tmpFoo, 'aList:', aList
# good examples at: http://effbot.org/zone/python-list.htm
### dictionary
aDict = {'blue':'blau', 'yellow':'gelb', 'pirated':'zugutenberg'}
print aDict
print 'get by key:', aDict['pirated']
# access a non existing key
#print 'get by key:', aDict['nope']
# add stuff
aDict['cat'] = 'Katze'
print aDict
# change stuff
aDict['cat'] = 'Hund'
print aDict