-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTuples.py
More file actions
48 lines (40 loc) · 984 Bytes
/
Tuples.py
File metadata and controls
48 lines (40 loc) · 984 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
# Tuples like Strings are immutable, but anytype
t = ('a', 'b', 'c', 'd', 'e')
t1 = ('a',) # one element
type(t1)
# or we can create with a function
t = tuple()
t = tuple('lupins')
print(t)
print(t[1:3])
# Compare Tuples
(0, 1, 2) < (0, 3, 4)
txt = 'but soft what light in yonder window breaks' words = txt.split()
t = list()
for word in words:
t.append((len(word), word))
print(t)
t.sort(reverse=True)
res = list()
for length, word in t:
res.append(word)
print(res)
# Atribuição de Tupla
m = [ 'se', 'divirta' ]
x, y = m
print(x)
print(y)
# Permutar valores das variaveis
x, y = y, x
# tupla de variaveis = tupla de expressoes
email = 'florzinha@hotmail.com'
nomedeusuario, dominiodoemail = email.split('@')
# Dictionaries and Tuples
d = {'a':10, 'b':1, 'c':22}
t = list(d.items())
print(t)
t.sort()
# Multipla atribuicao com Dicionarios
# percorrer a chave e valor de um dicionario em um unico item
for chave, valor in list(d.items()):
print(valor, chave)