[Tutor] String made of list elements' nth characters?

Alan Gauld alan.gauld at btinternet.com
Sun Apr 20 23:41:46 CEST 2008


"R. Alan Monroe" <amonroe at columbus.rr.com> wrote

> Given a list of 6-letter words:
> ['abject','poetry','keypad']
>
> How do I derive this list:
> ['apk', 'boe', 'jey']

>>> a = ['abject', 'poetry', 'keypad']
>>> zip( a[0],a[1],a[2])
[('a', 'p', 'k'), ('b', 'o', 'e'), ('j', 'e', 'y'), ('e', 't', 'p'), 
('c', 'r',
'a'), ('t', 'y', 'd')]
>>> [''.join(t) for t in zip(a[0],a[1],a[2])]
['apk', 'boe', 'jey', 'etp', 'cra', 'tyd']
>>>

Does that give you any ideas?


-- 
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld 




More information about the Tutor mailing list