-3

I want to print a dictionary in python.

menu = {
        1: ("Single Red Roses", 29),
        2: ("Burst of Spring Posy", 59),
        3: ("Super Grade Red Roses", 69),
        4: ("Lemon Gelato Roses", 79),
        5: ("Market Fresh Pin Lily", 79),
        6: ("Summer Daisy Gerbera", 79),
        7: ("Bag of Garden Roses", 89),
        8: ("Blue Lime Spring Rosy", 89),
        9: ("Hot Pink Roses", 89),
        10: ("Class White Roses", 99),
        11: ("Fresh Lime", 109),
        12: ("Boxed Red Roses", 129),
        13: ("Tropical Rain-forest Bouquet", 149),
    }

This is my code, I don't know how to do this becuz Im new thanks for the help :)

edit: how do I make it so that it prints each list one by one.

markiplier
  • 23
  • 9
  • Possible duplicate of [How do I print the key-value pairs of a dictionary in python](https://stackoverflow.com/questions/26660654/how-do-i-print-the-key-value-pairs-of-a-dictionary-in-python) – MFisherKDX Apr 11 '19 at 00:09
  • 2
    Does `print(menu)` not give you what you want? – MFisherKDX Apr 11 '19 at 00:10
  • If it's not `print(menu)` then I don't know what this question is asking for. – khelwood Apr 11 '19 at 00:18

2 Answers2

3
for key,val in menu.items():
    print(key + ": " + val)

Output:

    1: ("Single Red Roses", 29),
    2: ("Burst of Spring Posy", 59),
    3: ("Super Grade Red Roses", 69),
    4: ("Lemon Gelato Roses", 79),
    5: ("Market Fresh Pin Lily", 79),
    6: ("Summer Daisy Gerbera", 79),
    7: ("Bag of Garden Roses", 89),
    8: ("Blue Lime Spring Rosy", 89),
    9: ("Hot Pink Roses", 89),
    10: ("Class White Roses", 99),
    11: ("Fresh Lime", 109),
    12: ("Boxed Red Roses", 129),
    13: ("Tropical Rain-forest Bouquet", 149),
Saatvik
  • 117
  • 9
2

You cause use the built in print() function

print(menu)

{1: ('Single Red Roses', 29), 2: ('Burst of Spring Posy', 59), 3: ('Super Grade Red Roses', 69), 4: ('Lemon Gelato Roses', 79), 5: ('Market Fresh Pin Lily', 79), 6: ('Summer Daisy Gerbera', 79), 7: ('Bag of Garden Roses', 89), 8: ('Blue Lime Spring Rosy', 89), 9: ('Hot Pink Roses', 89), 10: ('Class White Roses', 99), 11: ('Fresh Lime', 109), 12: ('Boxed Red Roses', 129), 13: ('Tropical Rain-forest Bouquet', 149)}

For formatted output to the console, you can use the pprint module

import pprint

pp = pprint.PrettyPrinter(indent=4)
pp.pprint(menu)

which gives you

{   1: ('Single Red Roses', 29),
    2: ('Burst of Spring Posy', 59),
    3: ('Super Grade Red Roses', 69),
    4: ('Lemon Gelato Roses', 79),
    5: ('Market Fresh Pin Lily', 79),
    6: ('Summer Daisy Gerbera', 79),
    7: ('Bag of Garden Roses', 89),
    8: ('Blue Lime Spring Rosy', 89),
    9: ('Hot Pink Roses', 89),
    10: ('Class White Roses', 99),
    11: ('Fresh Lime', 109),
    12: ('Boxed Red Roses', 129),
    13: ('Tropical Rain-forest Bouquet', 149)}
nathancy
  • 42,661
  • 14
  • 115
  • 137