(No subject)

Jeremy Jones zanesdad at bellsouth.net
Thu Dec 16 17:18:43 CET 2004


Mark Devine wrote:

>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
>
>
>
>
>_________________________________________________________________
>Sign up for eircom broadband now and get a free two month trial.*
>Phone 1850 73 00 73 or visit http://home.eircom.net/broadbandoffer
>
>
>  
>
You could use string.lower (make sure you "import string"):

In [14]: commands
Out[14]:
['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']

In [15]: commands_lower = [string.lower(f) for f in commands]

In [16]: commands_lower
Out[16]:
['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']


Jeremy Jones



More information about the Python-list mailing list