"vince spicer" <vinces1...@gmail.com> wrote

Lambda can save the day to keep everything on one line, and leave variable
type the same:

mylist = ['John', 'Canada', 25, 32, 'right']
new_list = [(lambda y: y.upper() if hasattr(y, 'upper') else y)(a) for a in
mylist ]

>>  ['JACK', 'CANADA', 25, 32, 'RIGHT']

Vince


wrong var name "x", fixed



--------------------------------------------------------------------------------


_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor



_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to