Skip to content Skip to sidebar Skip to footer

Removing Brackets And Quotes From Print In Python 2.7

I am trying to remove the brackets from the print statement using Python 2.7 I tried suggestions from various forums but it didn't work as expected finally thought of asking out he

Solution 1:

re.findall returns a list. When you do str(someList), it will print the brackets and commas:

>>> l = ["a", "b", "c"]
>>> printstr(l)
['a', 'b', 'c']

If you want to print without [ and ,, use join:

>>>print' '.join(l)
a b c

If you want to print without [ but with ,:

>>>print', '.join(l)
a, b, c

And if you want to keep the ', you could use repr and list comprehension:

>>> print', '.join(repr(i) for i in l)
'a', 'b', 'c'

After your edit, it seems that there is only 1 element in your lists. So you can only print the first element:

>>>l = ['a']>>>print l
['a']
>>>print l[0]
a

Post a Comment for "Removing Brackets And Quotes From Print In Python 2.7"