I have a dictionary
>>>d = {"a":"apple", "c":"cat", "d":"dog"}
That dictionary should be printed to output in this particular format:
1. apple
2. cat
3. dog
If I have to use list comprehension to do so,
how would I go about getting it to also print the current iteration number i.e. 1 or 2 or 3 as per above output.
This is what I have so far and it just prints the dict values on newlines, but it is far from what I want.
>>>temp = "\n".join( [d[i] for i in d] )
>>>print temp
- Also, is it beneficial to use a generator instead of list comprehension here?
- Enviroment: Python 2.7
Sorted by value:
Sorted by key:
Unsorted (results will come out however
dictfeels like giving them)