turn text lines into a list

Discussion in 'Perl Misc' started by Xah Lee, Jun 27, 2005.

  1. Xah Lee

    Xah Lee Guest

    i have a large number of lines i want to turn into a list.
    In perl, i can do

    @corenames=qw(
    rb_basic_islamic
    sq1_pentagonTile
    sq_arc501Tile
    sq_arc503Tile
    );

    use Data::Dumper;
    print Dumper(\@corenames);

    ----------
    is there some shortcut to turn lines into list in Python?

    Xah

    ∑ http://xahlee.org/
     
    Xah Lee, Jun 27, 2005
    #1
    1. Advertising

  2. Xah Lee wrote:
    > i have a large number of lines i want to turn into a list.
    > In perl, i can do
    >
    > @corenames=qw(
    > rb_basic_islamic
    > sq1_pentagonTile
    > sq_arc501Tile
    > sq_arc503Tile
    > );


    Impractical to mix code and data, isn't it?

    chomp( my @corenames = <DATA> );

    __DATA__
    rb_basic_islamic
    sq1_pentagonTile
    sq_arc501Tile
    sq_arc503Tile

    --
    Gunnar Hjalmarsson
    Email: http://www.gunnar.cc/cgi-bin/contact.pl
     
    Gunnar Hjalmarsson, Jun 27, 2005
    #2
    1. Advertising

  3. Xah Lee

    Paul McGuire Guest

    Paul McGuire, Jun 27, 2005
    #3
  4. Xah Lee

    F. Petitjean Guest

    [En-tête "Followup-To:" positionné à comp.lang.python.]
    Le Mon, 27 Jun 2005 14:27:28 -0000, Grant Edwards a écrit :
    > On 2005-06-27, Xah Lee <> wrote:
    >> i have a large number of lines i want to turn into a list.
    >> In perl, i can do
    >>
    >> @corenames=qw(
    >> rb_basic_islamic
    >> sq1_pentagonTile
    >> sq_arc501Tile
    >> sq_arc503Tile
    >> );
    >>
    >> use Data::Dumper;
    >> print Dumper(\@corenames);
    >>
    >> ----------
    >> is there some shortcut to turn lines into list in Python?

    >
    > corenames = [ "rb_basic_islamic",
    > "sq1_pentagonTile",
    > "sq_arc501Tile",
    > "sq_arc503Tile"]
    >

    Another way : (less typing of quotes)

    all_names = """
    rb_basic_islamic
    sq1_pentagonTile
    sq_arc501Tile
    sq_arc503Tile
    """

    corenames = all_names.split()

    Regards.
     
    F. Petitjean, Jun 27, 2005
    #4
  5. Xah Lee

    Big and Blue Guest

    Gunnar Hjalmarsson wrote:
    >
    >> @corenames=qw(
    >> rb_basic_islamic
    >> sq1_pentagonTile
    >> sq_arc501Tile
    >> sq_arc503Tile
    >> );

    >
    >
    > Impractical to mix code and data, isn't it?


    Obviously not impractical, given he did it quite easily and succinctly.

    > chomp( my @corenames = <DATA> );
    >
    > __DATA__
    > rb_basic_islamic
    > sq1_pentagonTile
    > sq_arc501Tile
    > sq_arc503Tile


    Not so easy when you have multiple variables to set. And the original
    version was transparent in what it was doing - your version is not.


    --
    Just because I've written it doesn't mean that
    either you or I have to believe it.
     
    Big and Blue, Jun 28, 2005
    #5
    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. Xah Lee

    turn text lines into a list

    Xah Lee, Jun 27, 2005, in forum: Python
    Replies:
    8
    Views:
    490
    Big and Blue
    Jun 28, 2005
  2. mrstephengross
    Replies:
    5
    Views:
    414
  3. Eric Osman
    Replies:
    2
    Views:
    432
    Eric Osman
    Apr 14, 2004
  4. Mahurshi Akilla
    Replies:
    5
    Views:
    124
    Bart Lateur
    May 14, 2009
  5. seektime
    Replies:
    23
    Views:
    428
    Prasad, Ramit
    Oct 25, 2012
Loading...

Share This Page