[Tutor] String made of list elements' nth characters?
R. Alan Monroe
amonroe at columbus.rr.com
Sun Apr 20 18:01:00 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.
Per usual, I figured out a working approach right after posting. Could
probably be optimized, but it works:
def checksolution(sol):
maybes = []
big = ''.join(solution)
for x in range(len(sol)):
maybes.append( big[x::6] )
print maybes
solution=['abject','poetry','keypad']
checksolution(solution)
['apk', 'boe', 'jey']
Alan
More information about the Tutor
mailing list