Python Forum
Print Nested List Line by Line
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Print Nested List Line by Line
#2
Your idea is good. The thing you have to consider is that when you say
for i in list_mounts
you are picking each line at once out of the list. If you would say:
for x, y in list_mounts
you are picking each line and save the elements of the gotten line to x and y
so simply change your code to:
for x,y in list_mounts:
     print("Drive: ", x, "Used Space: ", y)
x and y are your values contained in the nested lists so that y becomes an integer so that you can not iterate over this (that was the first error.
The second error was due to you trying to call the list like a function list_mounts(x, y), but it is an Object of List and not a function, therefore you get the "object not callable" error.
The third error was due to the fact that you called a list with [x, y] x and y are interpreted as a tuple and that cannot be applied to lists, but it can to arrays ;) since it needs an integer it throws the "indices must be integers or slices, not tuple" error.
Reply


Messages In This Thread
Print Nested List Line by Line - by anelliaf - May-23-2018, 06:19 PM
RE: Print Nested List Line by Line - by ThiefOfTime - May-23-2018, 06:37 PM
RE: Print Nested List Line by Line - by anelliaf - May-23-2018, 06:38 PM
RE: Print Nested List Line by Line - by ThiefOfTime - May-23-2018, 06:41 PM
RE: Print Nested List Line by Line - by anelliaf - May-23-2018, 06:44 PM
RE: Print Nested List Line by Line - by buran - May-23-2018, 06:54 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Printing the code line number arbiel 6 423 Yesterday, 08:01 AM
Last Post: arbiel
  How to add multi-line comment section? Winfried 3 507 Jun-04-2024, 07:24 AM
Last Post: Gribouillis
Information Is it possible to multi line a Basic Function Construct line statement? If so how? BrandonKastning 7 529 May-23-2024, 03:02 PM
Last Post: deanhystad
  Line graph with two superimposed lines sawtooth500 4 537 Apr-02-2024, 08:56 PM
Last Post: sawtooth500
  break print_format lengthy line akbarza 4 550 Mar-13-2024, 08:35 AM
Last Post: akbarza
  Reading and storing a line of output from pexpect child eagerissac 1 4,560 Feb-20-2024, 05:51 AM
Last Post: ayoshittu
  coma separator is printed on a new line for some reason tester_V 4 673 Feb-02-2024, 06:06 PM
Last Post: tester_V
  problem with spliting line in print akbarza 3 555 Jan-23-2024, 04:11 PM
Last Post: deanhystad
  Unable to understand the meaning of the line of code. jahuja73 0 461 Jan-23-2024, 05:09 AM
Last Post: jahuja73
  Receive Input on Same Line? johnywhy 8 1,088 Jan-16-2024, 03:45 AM
Last Post: johnywhy

Forum Jump:

User Panel Messages

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