[Tutor] String made of list elements' nth characters?
R. Alan Monroe
amonroe at columbus.rr.com
Sun Apr 20 17:51:06 CEST 2008
Given a list of 6-letter words:
['abject','poetry','keypad']
How do I derive this list:
['apk', 'boe', 'jey']
(The original list's first letters, second letters, third letters,
etc.)
I have a text file of 15280 six-letter words and I want to robotically
generate 6x6 word squares.
My first attempt returns the right results, but _not in string form_.
There's bound to be a really simple approach that I'm just not
remembering.
def checksolution(sol):
maybes = []
for x in range(len(sol)):
maybes.append( [y[x] for y in sol] )
print maybes
solution=['abject','poetry','keypad']
checksolution(solution)
[['a', 'p', 'k'], ['b', 'o', 'e'], ['j', 'e', 'y']]
Alan
More information about the Tutor
mailing list