Reputation: 23
I wish for convert my for loop that contains if and else into single list expression line.
for k,v in zip(str+letters, str+letterb):
if v in "aeiou":
d[k] = v.upper()
else:
d[k] = v.lower()
into one line. The output doesnt matter because my code is correct when its like this
Upvotes: 1
Views: 67
Reputation: 498
You can use a dictionary comprehension
d = {k: (v.upper() if v in "aeiou" else v.lower()) for k,v in zip(str+letters, str+letterb)}
Upvotes: 1