Re: Character Sequence Generation
Pedro Werneck wrote: > On Thu, 22 Sep 2005 23:26:58 -0400 > Jeff Schwab <[EMAIL PROTECTED]> wrote: > > >>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... > Thanks, that's exactly what I want! -- http://mail.python.org/mailman/listinfo/python-list
Re: Character Sequence Generation
Jeff Schwab wrote: > What's the best way to generate a sequence of characters in Python? I'm > looking for something like this Perl code: 'a' .. 'z' . >>> import re >>> def char_set(a_z, all_chars="".join(map(chr, range(256: ... return re.compile("[%s]" % a_z).findall(all_chars) ... >>> for c in char_set("a-f0-9"): print c, ... 0 1 2 3 4 5 6 7 8 9 a b c d e f >>> for c in char_set("\s"): print repr(c), ... '\t' '\n' '\x0b' '\x0c' '\r' ' ' Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: Character Sequence Generation
Jeff Schwab wrote: > [EMAIL PROTECTED] wrote: > > Jeff Schwab wrote: > > > >>What's the best way to generate a sequence of characters in Python? I'm > >>looking for something like this Perl code: 'a' .. 'z' . > > > > > import string > > > > > print string.ascii_lowercase > > > > abcdefghijklmnopqrstuvwxyz > > Thanks. Is there a good way to generate the characters dynamically? ''.join([chr(i) for i in range(97,123)]) -- http://mail.python.org/mailman/listinfo/python-list
Re: Character Sequence Generation
On Thu, 22 Sep 2005 23:26:58 -0400 Jeff Schwab <[EMAIL PROTECTED]> wrote: > 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... -- Pedro Werneck -- http://mail.python.org/mailman/listinfo/python-list
Re: Character Sequence Generation
[EMAIL PROTECTED] wrote: > Jeff Schwab wrote: > >>What's the best way to generate a sequence of characters in Python? I'm >>looking for something like this Perl code: 'a' .. 'z' . > > import string > > print string.ascii_lowercase > > abcdefghijklmnopqrstuvwxyz Thanks. Is there a good way to generate the characters dynamically? -- http://mail.python.org/mailman/listinfo/python-list
Re: Character Sequence Generation
Jeff Schwab wrote: > What's the best way to generate a sequence of characters in Python? I'm > looking for something like this Perl code: 'a' .. 'z' . >>> import string >>> print string.ascii_lowercase abcdefghijklmnopqrstuvwxyz Others: ascii_letters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' ascii_lowercase = 'abcdefghijklmnopqrstuvwxyz' ascii_uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' digits = '0123456789' hexdigits = '0123456789abcdefABCDEF' letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuv...\xcd\xce... lowercase = 'abcdefghijklmnopqrstuvwxyz\x83\x9a\x9c\x9e\xaa\xb5\xba\xd... octdigits = '01234567' printable = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTU... punctuation = '!"#$%&\'()*+,-./:;<=>[EMAIL PROTECTED]|}~' uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ\x8a\x8c\x8e\x9f\xc0\xc1\xc2\xc... whitespace = '\t\n\x0b\x0c\r ' -- http://mail.python.org/mailman/listinfo/python-list