Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Dictionary Results Error
#1
Dear Programmers,

I hope you are having a wonderful sunday:

# the Program is meant to display the info from the dictionary, but instead is displaying letters.
Could you please help me solve the issue in my code.

mydata =  {'Stock1': [125, 772.88, 941.53],
          'Stock2': [85, 56.60, 73.04],
          'Stock3': [400, 49.58, 55.74],
          'Stock4': [235, 54.21, 65.27],
          'Stock5': [150, 124.31, 172.45]}

headers = ["Stock Symbol", "No Shares", "Purchase Price", "Current Value"]
separator1 = '+----------------+-------------+------------------+-----------------+'
separator2 = '+================+=============+==================+=================+'
print("\nStock Ownership")
print(separator1)
print('| {:14} | {:11} | {:16} | {:15} |'.format(*headers))
print(separator2)
for key, value in mydata.items():
    print('| {:14} | {:11} | {:16} | {:15} |'.format(*key, *value))
Output:
Stock Ownership +----------------+-------------+------------------+-----------------+ | Stock Symbol | No Shares | Purchase Price | Current Value | +================+=============+==================+=================+ | S | t | o | c | | S | t | o | c | | S | t | o | c | | S | t | o | c | | S | t | o | c |
Reply
#2
Dont provide the reference. Instead just the value should suffic. Remove the *.
Read about how to use * in python

    print('| {:14} | {:11} | {:16} | {:15} |'.format(key, *value))
Reply
#3
Thank you
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Compiling Python 3.8.5 source code results in build error Deepan 0 2,146 Sep-14-2020, 04:11 AM
Last Post: Deepan
  Search Results Web results Printing the number of days in a given month and year afefDXCTN 1 2,191 Aug-21-2020, 12:20 PM
Last Post: DeaD_EyE
  Error while checking for key in Dictionary onenessboy 5 2,595 Aug-14-2020, 01:06 PM
Last Post: onenessboy
  Importing module from a package results in import error goghvv 2 2,342 Mar-27-2020, 07:13 PM
Last Post: goghvv
  How to append one function1 results to function2 results SriRajesh 5 3,073 Jan-02-2020, 12:11 PM
Last Post: Killertjuh
  Is it possible to check for a key error in a python dictionary? mrsenorchuck 0 1,438 Dec-06-2019, 11:38 PM
Last Post: mrsenorchuck
  Calculation Inside Dictionary Error prophet11 3 2,558 Apr-22-2019, 05:23 AM
Last Post: perfringo
  Error 'object has no attribute' when iterating thru a dictionary mrapple2020 8 6,876 Apr-08-2019, 01:36 AM
Last Post: mrapple2020
  Error Handling/No results from SQL Query JP_ROMANO 7 9,273 Jul-18-2018, 02:31 PM
Last Post: JP_ROMANO

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020