J
Jeff Schwab
What's the best way to generate a sequence of characters in Python? I'm
looking for something like this Perl code: 'a' .. 'z' .
looking for something like this Perl code: 'a' .. 'z' .
abcdefghijklmnopqrstuvwxyzJeff said:What's the best way to generate a sequence of characters in Python? I'm
looking for something like this Perl code: 'a' .. 'z' .
abcdefghijklmnopqrstuvwxyz
Jeff said:Thanks. Is there a good way to generate the characters dynamically?
What's the best way to generate a sequence of characters in Python?
I'm looking for something like this Perl code: 'a' .. 'z' .
['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',[chr(x) for x in xrange(ord('a'), ord('z') + 1)]
['d', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p'][chr(x) for x in xrange(ord('d'), ord('p') + 1)]
['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N',[chr(x) for x in xrange(ord('A'), ord('Z') + 1)]
.... return re.compile("[%s]" % a_z).findall(all_chars)Jeff said:What's the best way to generate a sequence of characters in Python? I'm
looking for something like this Perl code: 'a' .. 'z' .
Pedro said:What's the best way to generate a sequence of characters in Python?
I'm looking for something like this Perl code: 'a' .. 'z' .
If you want arbitrary sequences, you may use something like:
[chr(x) for x in xrange(ord('a'), ord('z') + 1)]
['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
[chr(x) for x in xrange(ord('d'), ord('p') + 1)]
['d', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p']
[chr(x) for x in xrange(ord('A'), ord('Z') + 1)]
['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N',
'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
etc...
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.