This is a list of Integers and this is how they are printing:
[7, 7, 7, 7]
I want them to simply print like this:
7777
I don't want brackets, commas or quotes. What to do?
use join() function to print array or without square brackets or commas. The join() function takes an iterable object such as a list, tuple, dictionary, string, or set as an argument and returns a string in which all the elements are joined by a character specified with the function.
The join() function takes all the elements from an iterable object, like a list, and returns a string with all elements separated by a character specified with the function. Using this method, we can remove the square brackets from a list and separate the elements using a comma or whichever character we desire.
You can print a list without brackets by combining the string. join() method on the separator string ', ' with a generator expression to convert each list element to a string using the str() built-in function. Specifially, the expression print(', '.
If you're using Python 3, or appropriate Python 2.x version with from __future__ import print_function
then:
data = [7, 7, 7, 7] print(*data, sep='')
Otherwise, you'll need to convert to string and print:
print ''.join(map(str, data))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With