-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLoopingTechniques.py
More file actions
59 lines (39 loc) · 1.25 KB
/
LoopingTechniques.py
File metadata and controls
59 lines (39 loc) · 1.25 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
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/env python
# encoding: utf-8
"""
LoopingTechniques.py
Created by Marko on 2010-03-14.
Copyright (c) 2010 Bstards. All rights reserved.
"""
# Iterando dicionarios
mapaPaises = {'Mexico':"Ciudad de Mexico", 'Canada':"Ottawa", 'Francia':"Paris", 'Suiza':"Berna"}
for key, value in mapaPaises.iteritems():
print "Pais: ", key, ", su capital es: ", value
print 'Llaves: ', mapaPaises.keys()
print 'Valores: ', mapaPaises.values()
# Iterando una lista
print "====[Iterando la lista con indices]===="
listaRios = ['Panuco', 'Lerma', 'Usumacinta', 'Grijalva']
for index, value in enumerate( listaRios ):
print "Rio ", index, ": ", value
for index in range( len(listaRios) ):
print "Rio[", index, "]: ", listaRios[index]
"""
#
# La funcion 'zip' devuelve una tupla de las listas que se le pasen,
x = [1, 2, 3]
y = [4, 5, 6]
zipped = zip(x, y)
print zipped
x2, y2 = zip(*zipped)
print x2, ", " , list( x2 )
print y2, ", " , list( y2 )
"""
# Una forma de iterar varias listas se usa la funcion zip
listaPaises = mapaPaises.keys()
listaCiudades = mapaPaises.values()
tuplaPaisCiudad = zip(listaPaises, listaCiudades )
# Tupla Pais con ciudad
print tuplaPaisCiudad
for pais, ciudad in tuplaPaisCiudad:
print 'La ciudad de {0} es: {1}.'.format(pais, ciudad)