1

I have a list of lists and I want to remove all brackets, commands etc. ("[],'")

a=3
c=[["A ",["|   "]*a],
["  ",["|———"]*a],
["B ",["|   "]*a],
["  ",["|———"]*a],
["C ",["|   "]*a],
["  ",["|———"]*a]
]
for line in c:
    print(*line, sep="")

I want output like this:

A |   |   |   
  |———|———|———
B |   |   |   
  |———|———|———
C |   |   |   
  |———|———|———

But I'm getting this output:

A ['|   ', '|   ', '|   ']
  ['|———', '|———', '|———']
B ['|   ', '|   ', '|   ']
  ['|———', '|———', '|———']
C ['|   ', '|   ', '|   ']
  ['|———', '|———', '|———']

[Program finished]

3 Answers 3

2

Interesting question. I think the below does what you want with the given inputs.

for line in c:
    print("".join(["".join(x) for x in line]), sep="")
Sign up to request clarification or add additional context in comments.

Comments

2

Your problem is that you have three depths of nested lists

Depending your conditions, you can either change the way you generate your table, so that it only has two depths:

a=3
c=[["A "] + ["|   "]*a,
["  "] + ["|———"]*a,
["B "] + ["|   "]*a,
["  "] + ["|———"]*a,
["C "] + ["|   "]*a,
["  "] + ["|———"]*a
]
for line in c:
    print(*line, sep="")

... or change the way you print it:

a=3
c=[["A ",["|   "]*a],
["  ",["|———"]*a],
["B ",["|   "]*a],
["  ",["|———"]*a],
["C ",["|   "]*a],
["  ",["|———"]*a]
]
for head, line in c:
    print(head, *line, sep="")

Comments

1

Since "a"*3 is "aaa" in python you cana ctually use something like below.

a=3
c=[
    ["A ","|   "*a],
    ["  ","|———"*a],
    ["B ","|   "*a],
    ["  ","|———"*a],
    ["C ","|   "*a],
    ["  ","|———"*a]
]
for line in c:
    print(*line, sep="")

Output:

A |   |   |   
  |———|———|———
B |   |   |   
  |———|———|———
C |   |   |   
  |———|———|———

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.