2D Lists: sep="

Question (python) : I have a to-do 2D list but when i print it, it just prints spaces but I don’t want that so i want to introduce a sep="", but i am not sure where…?

Repl link:
https://replit.com/@DukeTI/Day45100Days#main.py

highPriority = [
    ["", "", ""],
    ["", "", ""],
    ["", "", ""],
    ["", "", ""],
]

image

Hi @DukeTI !
It’s printing blank because “” are just empty, so maybe try doing this instead:

highPriority = [ ['""', '""', '""'],
['""', '""', '""'],
['""', '""', '""'],
['""', '""', '""'], ]

This puts the " " in ' ' , so that " " will be printed.
Hope this helps!

1 Like

But for now, it will be empty but it prints some extra unnecessary lines that are blank as shown in the image. I would like for it to show nothing when it is blank(i.e so no extra lines)

If you want to introduce a separator while printing the elements in yours 2D list highPriority , you can use the join() method on the inner lists to concatenate their elements with a separator.

highPriority = [
    ["", "", ""],
    ["", "", ""],
    ["", "", ""],
    ["", "", ""],
]

separator = ", "

for row in highPriority:
    print(separator.join(row))
1 Like

I took a look at your code and… you have a lot of stuff to fix.
But if you want to print a 2D list but skip empty rows, you can do something like this.

for task in highPriority:
  if any(task):
    print(', '.join(task))

Though, I don’t know exactly how you would have a blank row in the first place.

1 Like