lowering the case of strings in list -- WAS: (No subject)

Discussion in 'Python' started by Brian van den Broek, Dec 16, 2004.

  1. Mark Devine said unto the world upon 2004-12-16 10:49:
    > Hi I'm brand new to python and I was wondering if anybody knew of a
    > easy way to change every character in a list into its lower case
    > form.
    >
    > The list is like so: commands = ['CLASS-MAP MATCH-ALL cmap1', 'MaTch
    > Ip AnY', 'CLASS-map Match-Any cmap2', 'MaTch AnY', 'Policy-map
    > policy1', 'Class cmap1', 'policy-Map policy2', 'Service-PoLicy
    > policy1', 'claSS cmap2']
    >
    > and what I want is: commands = ['class-map match-all cmap1', 'match
    > ip any', 'class-map match-any cmap2', 'match any', 'policy-map
    > policy1', 'class cmap1', 'policy-map policy2', 'service-policy
    > policy1', 'class cmap2']
    >
    > Are there any defined method within any known modules to do this in
    > one go?
    >
    > Thanks in advance


    Hi Mark,

    I'm learning, too, so no bets this is best, but does this meet your needs:

    ..>>> def lower_list_o_strings(l):
    nl = []
    for s in l:
    nl.append(s.lower())
    return nl

    ..>>> l = ['CLASS-MAP MATCH-ALL cmap1', 'MaTch Ip AnY', 'CLASS-map
    Match-Any cmap2', 'MaTch AnY', 'Policy-map policy1', 'Class cmap1',
    'policy-Map policy2', 'Service-PoLicy policy1', 'claSS cmap2']
    ..>>> lower_list_o_strings(l)
    ['class-map match-all cmap1', 'match ip any', 'class-map match-any
    cmap2', 'match any', 'policy-map policy1', 'class cmap1', 'policy-map
    policy2', 'service-policy policy1', 'class cmap2']


    Best,

    Brian vdB

    PS "No subject" is only marginally better than "HELP!!!!!!" ;-)
     
    Brian van den Broek, Dec 16, 2004
    #1
    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. Klaus Neuner
    Replies:
    7
    Views:
    498
    Klaus Neuner
    Jul 26, 2004
  2. Mark Devine
    Replies:
    2
    Views:
    281
    Mike Meyer
    Dec 16, 2004
  3. Divvy Bollocks
    Replies:
    1
    Views:
    335
    Gernot Frisch
    Mar 30, 2006
  4. anonym
    Replies:
    1
    Views:
    1,023
    Knute Johnson
    Jan 15, 2009
  5. jm

    lowering ruby's reach

    jm, Aug 1, 2005, in forum: Ruby
    Replies:
    8
    Views:
    216
Loading...

Share This Page