print(year '\ttable[year] life of brian holy grail the meaning of life same asfor year in table keys(the last command uses for loopwhich we previewed in but haven' covered in detail yet if you aren' familiar with for loopsthis command simply iterates through each key in the table and prints tab-separated list of keys and their values we'll learn more about for loops in dictionaries aren' sequences like lists and stringsbut if you need to step through the items in dictionaryit' easy--calling the dictionary keys method returns all stored keyswhich you can iterate through with for if neededyou can index from key to value inside the for loop as you goas was done in this code in factpython also lets you step through dictionary' keys list without actually calling the keys method in most for loops for any dictionary dsaying for key in works the same as saying the complete for key in keys(this is really just another instance of the iterators mentioned earlierwhich allow the in membership operator to work on dictionaries as wellmore on iterators later in this book previewmapping values to keys notice how the prior table maps year to titlesbut not vice versa if you want to map the other way--titles to years--you can either code the dictionary differentlyor use methods like items that give searchable sequencesthough using them to best effect requires more background information than we yet havetable {'holy grail'' ''life of brian'' ''the meaning of life'' 'table['holy grail'' key=>value (title=>yearlist(table items()value=>key (year=>title[('the meaning of life'' ')('holy grail'' ')('life of brian'' ')[title for (titleyearin table items(if year =' '['holy grail'the last command here is in part preview for the comprehension syntax introduced in and covered in full in in shortit scans the dictionary' (keyvaluetuple pairs returned by the items methodselecting keys having specified value the net effect is to index backward--from value to keyinstead of key to value--useful if you want to store data just once and map backward only rarely (searching through sequences like this is generally much slower than direct key indexdictionaries in action