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
| def f(x): return 2*x + 0.4
li = [ 12,'orange',34,('ui',345),23,24,25,{'lu':222,'lo':455},98,f,467,[1,24,23,5,47],90,34,99]
print 'li =\n',li
IT = iter(li)
print '\nIT = iter(li) type(IT) =',type(IT)
print '\n\n-- Premiere boucle dans iterateur IT ---------------------'
for i,x in enumerate(IT):
if type(x)==type(1):
try: print IT.next()
except: pass
print '-- Deuxieme boucle dans iterateur IT ---------------------'
for j,u in enumerate(IT):
if type(u)==type(1):
try: print IT.next()
except: pass
print '\n\n============================================='
it2 = iter(li)
L = list(it2)
print '-- Premiere boucle dans liste L ----------'
for i,x in enumerate(L):
if type(x)==type(1):
try: print L[i+1]
except: pass
print '-- Deuxieme boucle dans liste L ----------'
for i,x in enumerate(L):
if type(x)==type(1):
try: print L[i+1]
except: pass |
Partager