HELP ); "Python Language"

TZ boy

JF-Expert Member
Jan 11, 2012
624
181
what is exactly difference between zip() and map() in python it seems to brig the same answer when u execute block one and block two codes ? some one can tell me in simple way so that i can understand more about this two function ?


L1 = (1, 3, 4, 6)
L2 = (3, 5, 6, 2)

// block one
print zip(L1, L2)
for (x, y) in zip(L1, L2):
print x, y, '=', x + y

// block two
print map(None, L1, L2)
for (z, t) in map(None, L1, L2):
print z, t, '=', z + t
 
what is exactly difference between zip() and map() in python it seems to brig the same answer when u execute block one and block two codes ? some one can tell me in simple way so that i can understand more about this two function ?


L1 = (1, 3, 4, 6)
L2 = (3, 5, 6, 2)

// block one
print zip(L1, L2)
for (x, y) in zip(L1, L2):
print x, y, '=', x + y

// block two
print map(None, L1, L2)
for (z, t) in map(None, L1, L2):
print z, t, '=', z + t


Utofauti wake ni huu hapa:
zip function yenyewe ita~map elents zilizopo kwenye list moja into list nyingine in a way that kama list moja ina number of items less than the other basi ita~map only until elements of one of the lists have been matched completely then ita~acha the rest of the values out, Lakini unavotumia map ndio maana unaanza na parameter 'None' yaani hata kama element itakosa mwenzake itakua mapped to None mfano:

L1 = (a, b, c)
L2 = (w, x, y, z,1)

zip (L1, L2) - (a, w) (b,x) (c, y)
map(None, L1, L2) -(a, w) (b,x) (c, y) (None, z)(None,1)

Kwa hiyo change the length of your lists then try again, you'll notice the difference.

Alafu these kinda small stuffs as a programmer em jifunze ku~google around, I'm sure u can find your answer in less than 30seconds, way quicker than the time u used to write this post.
 
Utofauti wake ni huu hapa:
zip function yenyewe ita~map elents zilizopo kwenye list moja into list nyingine in a way that kama list moja ina number of items less than the other basi ita~map only until elements of one of the lists have been matched completely then ita~acha the rest of the values out, Lakini unavotumia map ndio maana unaanza na parameter 'None' yaani hata kama element itakosa mwenzake itakua mapped to None mfano:

L1 = (a, b, c)
L2 = (w, x, y, z,1)

zip (L1, L2) - (a, w) (b,x) (c, y)
map(None, L1, L2) -(a, w) (b,x) (c, y) (None, z)(None,1)

Kwa hiyo change the length of your lists then try again, you'll notice the difference.

Alafu these kinda small stuffs as a programmer em jifunze ku~google around, I'm sure u can find your answer in less than 30seconds, way quicker than the time u used to write this post.
Okey... thanks sana mkuu!
 
Back
Top Bottom