Re: split

Discussion in 'Python' started by Joachim Bauch, Jun 11, 2004.

  1. -----BEGIN PGP SIGNED MESSAGE-----
    Hash: SHA1

    Gandalf wrote:
    |
    | This way:
    |
    | >>> s = 'some string'
    | >>> l = []
    | >>> for c in s:
    | ... l.append(c)
    | ...
    | >>> l
    | ['s', 'o', 'm', 'e', ' ', 's', 't', 'r', 'i', 'n', 'g']
    | >>>

    an even faster way would be

    |>> s = 'another string'
    |>> l = [ch for ch in s]
    |>> l
    ['a', 'n', 'o', 't', 'h', 'e', 'r', ' ', 's', 't', 'r', 'i', 'n', 'g']

    Joachim

    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v1.2.4 (MingW32)
    Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

    iD8DBQFAyZy9vb5cTc087cURAnUDAJ46B7Gikydj3yG2R9nK46M5/S4SngCfT0Fk
    ENK4radRa34QXpF4Gi1GROo=
    =LB+K
    -----END PGP SIGNATURE-----
     
    Joachim Bauch, Jun 11, 2004
    #1
    1. Advertising

  2. Joachim Bauch

    Peter Otten Guest

    Joachim Bauch wrote:

    > Gandalf wrote:
    > |
    > | This way:
    > |
    > | >>> s = 'some string'
    > | >>> l = []
    > | >>> for c in s:
    > | ... l.append(c)
    > | ...
    > | >>> l
    > | ['s', 'o', 'm', 'e', ' ', 's', 't', 'r', 'i', 'n', 'g']
    > | >>>
    >
    > an even faster way would be
    >
    > |>> s = 'another string'
    > |>> l = [ch for ch in s]
    > |>> l
    > ['a', 'n', 'o', 't', 'h', 'e', 'r', ' ', 's', 't', 'r', 'i', 'n', 'g']


    >>> list("or even")

    ['o', 'r', ' ', 'e', 'v', 'e', 'n']
    >>>


    Peter
     
    Peter Otten, Jun 11, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    2
    Views:
    492
  2. Carlos Ribeiro
    Replies:
    11
    Views:
    741
    Alex Martelli
    Sep 17, 2004
  3. trans.  (T. Onoma)

    split on '' (and another for split -1)

    trans. (T. Onoma), Dec 27, 2004, in forum: Ruby
    Replies:
    10
    Views:
    240
    Florian Gross
    Dec 28, 2004
  4. Sam Kong
    Replies:
    5
    Views:
    278
    Rick DeNatale
    Aug 12, 2006
  5. Stanley Xu
    Replies:
    2
    Views:
    713
    Stanley Xu
    Mar 23, 2011
Loading...

Share This Page