Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to print a list without it showing brackets and "" in the output ? Python 3.3.2 [duplicate]

So say I have a list named myList and it looks something like this :

myList = ["a", "b", "c"]

How would you print it to the screen so it prints :

abc 

(yes, no space inbetween)

If I use print(myList) It prints the following:

['a', 'b', 'c']

Help would be much appreciated.

like image 249
dkentre Avatar asked Dec 02 '22 21:12

dkentre


2 Answers

With Python 3, you can pass a separator to print. * in front of myList causes myList to be unpacked into items:

>>> print(*myList, sep='')
abc
like image 187
iruvar Avatar answered Dec 09 '22 15:12

iruvar


Use str.join():

''.join(myList)

Example:

>>> myList = ["a", "b", "c"]
>>> print(''.join(myList))
abc

This joins every item listed separated by the string given.

like image 23
TerryA Avatar answered Dec 09 '22 15:12

TerryA