N
N
nihi1ist2021-09-24 15:41:28
Python
nihi1ist, 2021-09-24 15:41:28

How to insert the only value of a list without brackets?

A list is formed, it can contain only one value. When inserting using the method join(), extra elements appear:

numbers = [3]
print(', '.join(numbers)
[, 3, ]

Tell me how to insert a single value from the list without brackets and extra elements?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vladimir Kuts, 2021-09-24
@nihi1ist

print(', '.join(map(str, filter(bool, numbers))))
if i understand the problem correctly

V
Vindicar, 2021-09-24
@Vindicar

The given code is syntactically incorrect, and should not give such behavior.
So what you launch is not what you bring here.
How do you declare a list?
Isn't
numbers = "[3]" a case?
Or maybe
numbers = input() #type [3]
Because in that case, the observed behavior will be exactly what you describe.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question