Puzzled

Colin J. Williams cjw at sympatico.ca
Tue Jul 12 04:10:33 CEST 2005


The snippet of code below gives the result which follows

for k in ut.keys():
   name= k.split('_')
   print '\n1', name
   if len(name) > 1:
     name[0]= name[0] + name[1].capitalize()
     print '2', name
   name[0]= name[0].capitalize()
   print '3', name

1 ['logical', 'or']
2 ['logicalOr', 'or']
3 ['Logicalor', 'or']

I was expecting that 3 would read ['LogicalOr', 'or']

If I replace the above code with:

for k in ut.keys():
   name= k.split('_')
   print '\n1', name
   if len(name) > 1:
     name[0]= name[0].capitalize() + name[1].capitalize()
     print '2', name
   else:
     name[0]= name[0].capitalize()
   print '3', name

I get the desired result.

Colin W.



More information about the Python-list mailing list