0
$\begingroup$

Here's something I just quickly typed into the "Python Console" which perfectly shows the problem I'm having:

>>> list = []
>>> word = "something"
>>> list.extend(word)
>>> print(list)
['s', 'o', 'm', 'e', 't', 'h', 'i', 'n', 'g']

I want to know how I can make it so that it adds "something" as just one thing. So that when I type print(list) the outcome looks like this:

>>> print(list)
['something']
$\endgroup$

1 Answer 1

1
$\begingroup$

you defined list as an array and the python console prints an array as single elements. So either define it as string or combine it to one string before printing.

or did you search for append?

list = []
word = "something"
list.append(word)
print(list)

maybe this explains it a bit: https://www.geeksforgeeks.org/append-extend-python/

$\endgroup$
1
  • $\begingroup$ Using list.append did the trick. Thank you! $\endgroup$
    – ColinT
    Oct 11, 2022 at 13:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .