If you are not already familiar with Python REPL (Read-Evaluate-Print-Loop is where you enter the code, press Enter and it will appreciate right away), this would be a good tool here.
So, let's start breaking your code.
crucial = {'eggs': '','ham': '','cheese': ''} dishes = {'eggs': 2, 'sausage': 1, 'bacon': 1, 'spam': 500}
Simple enough. Although I note that you have no meanings in the crucials dictionary. I'm not sure if this is an abbreviation for an example or if you just care about the keys. If you only care about keys, then I assume that you use a dictionary to ensure uniqueness. In this case, you should check the set structure.
Example:
crutial = set(['cheese', 'eggs', 'ham'])
Continuing, we have
if crucial.keys() in dishes.keys():
here you use the comparison operator in . Example:
5 in [5, 4] #True 3 in [5, 4] #False
If we evaluate crucial.keys() and dishes.keys() , we get
>>> crucial.keys() ['cheese', 'eggs', 'ham'] >>> dishes.keys() ['eggs', 'bacon', 'sausage', 'spam']
therefore, at runtime, your code evaluates to
['cheese', 'eggs', 'ham'] in ['eggs', 'bacon', 'sausage', 'spam']
which returns False because the value of ['eggs', 'bacon', 'sausage'] (which is the list) is not in the list ['eggs', 'bacon', 'sausage', 'spam'] (actually in there are no lists in this list, only lines).
So you rate how
if False: print dishes[value]
Most likely, you mixed / confused the in operator, which returns a boolean and an iterator ( for item in collection ). There is a syntax for these kinds of things. It's called a list of concepts , which you can find in the answers of @ShawnZhang and @kmad. You can think of it as a complicated way to filter and modify (display) a collection, returning a list as a result. I do not want to delve into it, or I will talk about functional programming.
Another option is to use the for .. in operators of iteration and in separately. This solution by @timc gave. Such solutions are probably more familiar or easier for beginners. It clearly separates the iteration and filtering behavior. It also looks more like what would be written in other programming languages ββthat have no equivalent for list comprehension. Those who work a lot in Python are likely to prefer the understanding syntax.