dict() constructor builds dictionaries directly from lists of key-value pairs : Dictionary Declaration : Dictionary PYTHON examples


PYTHON examples » Dictionary » Dictionary Declaration »

 

dict() constructor builds dictionaries directly from lists of key-value pairs



# dict() constructor builds dictionaries directly from lists of key-value pairs stored 
# as tuples. 


print dict([('sape', 4139)('guido', 4127)('jack', 4098)])

print dict([(x, x**2for x in (246)])     # use a list comprehension


# When the keys are simple strings, it is sometimes easier to specify pairs using 
# keyword arguments:

print dict(sape=4139, guido=4127, jack=4098)



           
       



Leave a Comment / Note


 
Verification is used to prevent unwanted posts (spam). .


PYTHON examples

 Navioo Dictionary
» Dictionary Declaration