Generate alphabet?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • ssecorp

    Generate alphabet?

    In Haskell I can do [1..10] for range(1,11) and ['a'..'z'] for a list
    of the alphabet.

    Is there a way in Python to generate chars?
  • Wojtek Walczak

    #2
    Re: Generate alphabet?

    On Fri, 22 Aug 2008 15:02:19 -0700 (PDT), ssecorp wrote:
    In Haskell I can do [1..10] for range(1,11) and ['a'..'z'] for a list
    of the alphabet.
    >
    Is there a way in Python to generate chars?
    It's not actually about generating anything, but why should
    one generate something if it's accessible anyway:

    import string
    print string.letters

    --
    Regards,
    Wojtek Walczak,
    Cena domeny: 4999 PLN (do negocjacji). Możliwość kupna na raty od 624.88 PLN miesięcznie. Oferta sprzedaży znajduje się w serwisie Aftermarket.pl, największej giełdzie domen internetowych w Polsce.

    Comment

    • Emile van Sebille

      #3
      Re: Generate alphabet?

      ssecorp wrote:
      In Haskell I can do [1..10] for range(1,11) and ['a'..'z'] for a list
      of the alphabet.
      >
      Is there a way in Python to generate chars?
      How about:

      def haskellrange(sc ,ec):
      if type(sc) is int:
      for ii in range(sc,ec):
      yield ii
      else:
      for ii in range(ord(sc),o rd(ec)+1):
      yield chr(ii)


      for jj in haskellrange(1, 10): jj

      for jj in haskellrange('a ','z'): jj


      Add salt to taste...

      Emile

      Comment

      • Medardo Rodriguez (Merchise Group)

        #4
        Re: Generate alphabet?

        On Fri, Aug 22, 2008 at 6:02 PM, ssecorp <circularfunc@g mail.comwrote:
        .['a'..'z'] for a list of the alphabet.
        >
        Is there a way in Python to generate chars?

        Not as nice as in Haskell (or other languages), but:

        [chr(i) for i in xrange(ord('a') , ord('z')+1)]

        Regards

        Comment

        • Leo Jay

          #5
          Re: Generate alphabet?

          On Sat, Aug 23, 2008 at 6:02 AM, ssecorp <circularfunc@g mail.comwrote:
          In Haskell I can do [1..10] for range(1,11) and ['a'..'z'] for a list
          of the alphabet.
          >
          Is there a way in Python to generate chars?
          >
          how about:
          >>import string
          >>','.join(stri ng.ascii_lowerc ase)
          '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'
          >>>

          --
          Best Regards,
          Leo Jay

          Comment

          Working...