Sign Up

Have an account? Sign In Now

Sign In

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

Sorry, you do not have a permission to ask a question, You must login to ask question.

Forgot Password?

Need An Account, Sign Up Here
Sign InSign Up

ErrorCorner

ErrorCorner Logo ErrorCorner Logo

ErrorCorner Navigation

  • Home
  • Contact Us
  • About Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Contact Us
  • About Us
Home/ Questions/Q 549
Next
Answered
Kenil Vasani
Kenil Vasani

Kenil Vasani

  • 646 Questions
  • 567 Answers
  • 77 Best Answers
  • 26 Points
View Profile
  • 4
Kenil Vasani
Asked: December 14, 20202020-12-14T21:04:37+00:00 2020-12-14T21:04:37+00:00In: Python

TypeError: unsupported format string passed to list.__format__

  • 4

I have two list named results and p_results. I want to show those list values in table like if

results = [1,2,3,4]
p_results = [5,6,7,8]

I want something like this

1     5
2     6
3     7
4     8

        print('{:3}{:20}'.format(results, p_results))

running the code:

runfile('D:/4/2d.py', wdir='D:/4')
Traceback (most recent call last):

  File "<ipython-input-59-1abb0c96f0c0>", line 1, in <module>
    runfile('D:/4/2d.py', wdir='D:/4')

  File "C:\Users\Rabinsen\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 668, in runfile
    execfile(filename, namespace)

  File "C:\Users\Rabinsen\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 108, in execfile
    exec(compile(f.read(), filename, 'exec'), namespace)

  File "D:/4/2d.py", line 61, in <module>
    print('{:3}{:20}'.format(results, p_results))

TypeError: unsupported format string passed to list.__format__
python
  • 1 1 Answer
  • 10 Views
  • 0 Followers
  • 0
Answer
Share
  • Facebook

    1 Answer

    • Voted
    1. Kenil Vasani

      Kenil Vasani

      • 646 Questions
      • 567 Answers
      • 77 Best Answers
      • 26 Points
      View Profile
      Best Answer
      Kenil Vasani
      2020-12-14T21:02:23+00:00Added an answer on December 14, 2020 at 9:02 pm

      You can pass a list type to format (using just {}), but the formatting you requested isn’t available. And the standard formatting isn’t suited anyway, so…

      What you want is each list on one separate column. You’ll have to zip lists together, and iterate on the result to pass it to format:

      results = [1,2,3,4]
      p_results = [5,6,7,8]
      
      for result,p_result in zip(results,p_results):
          print('{:3}{:20}'.format(result,p_result))
      

      That prints something like:

        1                   5
        2                   6
        3                   7
        4                   8
      
      • 0
      • Share
        Share
        • Share on Facebook
        • Share on Twitter
        • Share on LinkedIn
        • Share on WhatsApp

    You must login to add an answer.

    Forgot Password?

    Sidebar

    Ask A Question
    • Popular
    • Kenil Vasani

      SyntaxError: invalid syntax to repo init in the AOSP code

      • 5 Answers
    • Kenil Vasani

      runtimeError: package fails to pass a sanity check for numpy ...

      • 3 Answers
    • Kenil Vasani

      xlrd.biffh.XLRDError: Excel xlsx file; not supported

      • 3 Answers
    • Kenil Vasani

      Homebrew fails on MacOS Big Sur

      • 3 Answers
    • Kenil Vasani

      SQLSTATE[HY000]: General error: 1835 Malformed communication packet on LARAVEL

      • 2 Answers

    Explore

    • Most Answered
    • Most Visited
    • Most Voted
    • Random

    © 2020-2021 ErrorCorner. All Rights Reserved
    by ErrorCorner.com