Header Ads

Responsive Ads Here

Dictionary Comprehension-2

 Dictionary Comprehension



d = {}
for i in range(1,11):
    if i % 2 == 0:
        d[i] = "Even"
    else:
        d[i] = "Odd"
print(d)

d1 = {i: ("Even" if i % 2 == 0 else "Odd") for i in range(1,11)}
print(d1)

Powered by Blogger.