Newbie: Struggling again 'map'

Dan Bishop danb_83 at yahoo.com
Sat May 26 06:21:16 EDT 2007


On May 26, 4:54 am, mosscliffe <mcl.off... at googlemail.com> wrote:
> I thought I had the difference between 'zip' and 'map' sorted but when
> I try to fill missing entries with something other than 'None'. I do
> not seem to be able to get it to work - any pointers appreciated.
>
> Richard
>
> lista = ['a1', 'a2']
> listb = ['b10', 'b11','b12' ,'b13']
>
> for x,y in zip(lista, listb):    #  Fine Truncates as expected
>     print "ZIP:", x, "<<x  y>>", y
>
> for x,y in map(None, lista, listb):  #  Also fine - extends as
> expected
>     print "MAP:", x, "<<x  y>>", y
>
> for x,y in map("N/A", lista, listb): ########## Fails - Can not call a
> 'str'
>     print "MAP:", x, "<<x  y>>", y
>
> def fillwith(fillchars):
>     return fillchars
>
> for x,y in map(fillwith("N/A"), lista, listb): ########## Fails also -
> Can not call a 'str'
>     print "MAP:", x, "<<x  y>>", y

zip(lista + ['N/A'] * 2, listb)




More information about the Python-list mailing list