-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtuples.py
More file actions
47 lines (38 loc) · 1.01 KB
/
tuples.py
File metadata and controls
47 lines (38 loc) · 1.01 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
41
42
43
44
45
46
47
# Tuples sre immutable
te = (2, "some", 42)
answer = te[2]
#slice tuple
some_answer = te[1:3]
print(te, answer, some_answer)
# Concatenate tuples
ste = te + (5, 55)
print(ste)
x = 3
y = 73
# Using tuple for swaping variables
(x, y) = (y, x)
print(x, y)
# Using tuple to return more than one value from a function
def qq(x, y):
q = x // y
r = x % y
return (q, r)
(x, y) = qq(x, y)
print(x, y)
def get_data(aTuple):
nums = ()
words = ()
for t in aTuple:
#it is important to add a comma for program to understand that it is tuple with single element
nums = nums + (t[0],)
if t[1] not in words:
words = words + (t[1],)
min_nums = min(nums)
max_nums = max(nums)
unique_words = len(words)
return (min_nums, max_nums, unique_words)
(small, large, words) = get_data(((1, "mine"),
(3, "yours"),
(5, "ours"),
(7, "mine")))
print (small, large, words)