using str format(with mapping unpacking collection data types although dictionary of web sites is likely to contain lot of itemsmany other dictionaries have only few items for small dictionarieswe can print their contents using their keys as field names and using mapping unpacking to convert the dictionary' key-value items into key-value arguments for the str format(method mapping unpacking greens dict(green="# "olive="# "lime="# ff "print("{green{olive{lime}format(**greens)# # # ff hereusing mapping unpacking (**has exactly the same effect as writing format(green=greens greenolive=greens olivelime=greens lime)but is easier to write and arguably clearer note that it doesn' matter if the dictionary has more keys than we needsince only those keys whose names appear in the format string are used dictionary comprehensions dictionary comprehension is an expression and loop with an optional condition enclosed in bracesvery similar to set comprehension like list and set comprehensionstwo syntaxes are supported{keyexpressionvalueexpression for keyvalue in iterable{keyexpressionvalueexpression for keyvalue in iterable if conditionhere is how we could use dictionary comprehension to create dictionary where each key is the name of file in the current directory and each value is the size of the file in bytesfile_sizes {nameos path getsize(namefor name in os listdir(")the os ("operating system"module' os listdir(function returns list of the files and directories in the path it is passedalthough it never includes or in the list the os path getsize(function returns the size of the given file in bytes we can avoid directories and other nonfile entries by adding conditionfile_sizes {nameos path getsize(namefor name in os listdir("if os path isfile(name)the os path module' os path isfile(function returns true if the path passed to it is that of fileand false otherwise--that isfor directorieslinksand so on dictionary comprehension can also be used to create an inverted dictionary for examplegiven dictionary dwe can produce new dictionary whose keys are ' values and whose values are ' keysos and os path modules