[Tutor] Problem with code interating thri a list
Alan Gauld
alan.gauld at yahoo.co.uk
Tue Aug 2 19:55:41 EDT 2016
On 03/08/16 00:30, Alan Gauld via Tutor wrote:
>> if item == item.lower():
I meant to add that the string islower() method is probably
more readable:
if item.islower()
Also that you could use a list comprehension to do this without
converting to a list initially:
def conveert(text):
result_list = [ch.upper() if ch.islower() else ch.lower()
for ch in text]
return ''.join(result_list)
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos
More information about the Tutor
mailing list