-
Notifications
You must be signed in to change notification settings - Fork 0
/
week5 24.11.2019 Note.txt
115 lines (90 loc) · 2.24 KB
/
week5 24.11.2019 Note.txt
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
a = [-1, 1, 66.25, 333, 333, 1234.5]
del a[0]
a
del a[3]
a
a.append(50)
a.append(100)
a.append(150)
>>> u[0] = 3, 4, 5, 6, 7, 8
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'tuple' object does not support item assignment
>>> u[0] = 98765
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'tuple' object does not support item assignment
>>> u[0] = 7, (3, 4, 5, 6, 7, 8, 9)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'tuple' object does not support item assignment
>>> t[0] = 12345
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'tuple' object does not support item assignment
v = ([1, 2, 3], [3, 2, 1])
v
([1, 2, 3], [3, 2, 1])
x = ([5, 6, 7], [8, 5, 9])
z = v + x
z
([1, 2, 3], [3, 2, 1], [5, 6, 7], [8, 5, 9])
z[0]
[1, 2, 3]
>>> empty = ()
>>> singleton = 'hello'
>>> len(empty)
0
>>> len(singleton)
5
>>> singleton = 'hello','world'
>>> len(singleton)
2
set >> for unordered collection
>>> basket = {'apple', 'orange', 'apple', 'pear', 'orange', 'banana'}
>>> print(basket)
{'pear', 'banana', 'apple', 'orange'}
>>> basket = {'banana', 'apple', 'cucumber', 'pineapple', 'orange', 'grape', 'apple', 'banana'}
>>> print(basket)
{'cucumber', 'pineapple', 'banana', 'grape', 'orange', 'apple'}
>>> print(basket)
{'cucumber', 'pineapple', 'banana', 'grape', 'orange', 'apple'}
>>> 'orange' in basket
True
>>> 'grass' in basket
a = set('mgmgmamamyamyaayeaye')
a
{'a', 'm', 'g', 'y', 'e'}
>>> b = set('kokoaungaungkyikyikyukyu')
>>> b
{'o', 'a', 'i', 'g', 'k', 'u', 'y', 'n'}
>>> c = set('1234567890')
>>> c
{'2', '7', '3', '9', '5', '8', '6', '1', '4', '0'}
>>> a - b
{'e', 'm'}
>>> a
{'a', 'm', 'g', 'y', 'e'}
>>> b
{'o', 'a', 'i', 'g', 'k', 'u', 'y', 'n'}
>>> a - b
{'e', 'm'}
>>> a | b
{'o', 'a', 'm', 'i', 'g', 'k', 'u', 'y', 'n', 'e'}
>>> a & b
{'g', 'y', 'a'}
>>> a ^ b
{'o', 'i', 'm', 'k', 'u', 'n', 'e'}
>>> b - a
{'o', 'i', 'k', 'u', 'n'}
>>> b | a
{'o', 'a', 'i', 'm', 'g', 'k', 'u', 'y', 'n', 'e'}
>>> b & a
{'g', 'y', 'a'}
>>> b ^ a
{'o', 'i', 'm', 'k', 'u', 'n', 'e'}
>>> c - b - a
{'2', '9', '3', '7', '5', '8', '6', '1', '4', '0'}
>>> a = {x for x in 'mgmgmamamyamyaayeaye' if x not in 'agye'}
>>> a
{'m'}