please don't close this, since i'm a newbie to py3. Help me to "convert" from a list-comprehension with both: for-in & if-in... to "normal" python3 code with loops & conditions:
Why the hassle? Because frankly it will help me understand both of the concepts, since i've just started with py3, it makes me anxious... really badly.
# here is the original code that needs conversion...
friends = ["Wolf", "Frootie", "charlean", "Jenny"]
guests = ["xavier", "Bobbie", "wolf", "Charlean", "ashley"]
friends_lcase = [f.lower() for f in friends]
#guests_lcase = [g.lower() for g in guests]
present_friends = [
name.title() for name in guests if name.lower() in friends_lcase
]
print(present_friends)
# here below should be the equivalent of
# the above code, which is the issue for me...
# i tried the next but failed, help:
present_friends_2 = []
for i in friends:
if i.lower() in guests:
present_friends_2.append(i)
else:
present_friends_2.append(0)
print(present_friends_2)
Aucun commentaire:
Enregistrer un commentaire