Posted by : ANIL KUMAR MULA Friday, 2 January 2015

python comprehension is a good construct with that code is compressed to a greater extent. here is a sample example given for that.





#print even numbers from 1 to 10; 2 4 6 8
print([i for i in range(1,11) if i % 2 == 0])


#print dictionary; key as key and value as length of key
print({i:len(i) for i in ["python","ruby","c"]  })

Leave a Reply

Subscribe to Posts | Subscribe to Comments

- Copyright © Anil Kumar Mula - Skyblue - Powered by Blogger - Designed by Johanes Djogan -