import os # from a directory get each file name as key and file size as value print {filename: os.path.getsize(filename) for filename in os.listdir(os.getcwd()) } # initialize from 0-9 key as true print {n: True for n in range(10)}
Friday, December 20, 2013
python dictionary comprehensions
Python dictionary comprehensions is similar to list comprehension. Lets have some example
Posted by
Abu Zahed Jony
at
5:58 PM
Email ThisBlogThis!Share to XShare to FacebookShare to Pinterest
Labels:
dictionary,
pythonic
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment