-5

hi how can i display each value from the dictionary below
product = {'barcode': [123, 456], 'Name': ['Milk', 'Bread'], 'Price': ['2', '3.5'], 'weight': ['2', '0.6']}

i want output as:

123  Milk  2 

456  Bread 3.5
Nabeinz kc
  • 29
  • 5
  • can you please provide me the code ..for doing so @AnttiHaapala – Nabeinz kc Apr 26 '18 at 05:30
  • i don't want to change further coz i have to modify entire program. The problem is i have a empty dictionary call PRODUCT where i am appending the data taken from user so the dictionary now contains above data and i have to print other output as displayed above. @AnttiHaapala – Nabeinz kc Apr 26 '18 at 05:37

1 Answers1

0

You can use pandas.

import pandas as pd

product = {'barcode': [123, 456], 'Name': ['Milk', 'Bread'], 
           'Price': ['2', '3.5'], 'weight': ['2', '0.6']}

df = pd.DataFrame(product)

for _, row in df.iterrows():
    print(row['barcode'], row['Name'], row['Price'])

123 Milk 2
456 Bread 3.5

Edit:

Using pure Python:

product = {'barcode': [123, 456], 'Name': ['Milk', 'Bread'], 
           'Price': ['2', '3.5'], 'weight': ['2', '0.6']}

for tup in zip(*list(product.values())[:-1]):
    print(*tup)

123 Milk 2
456 Bread 3.5
srikavineehari
  • 2,502
  • 1
  • 11
  • 21