34

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?

Ronak Shah
  • 355,584
  • 18
  • 123
  • 178
Doug
  • 389
  • 1
  • 3
  • 8

5 Answers5

80

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))
Jon Clements
  • 132,101
  • 31
  • 237
  • 267
15

Try this:

print("".join(str(x) for x in This))
zwol
  • 129,170
  • 35
  • 235
  • 347
9

Using .format from Python 2.6 and higher:

>>> print '{}{}{}{}'.format(*[7,7,7,7])
7777
>>> data = [7, 7, 7, 7] * 3
>>> print ('{}'*len(data)).format(*data)
777777777777777777777777

For Python 3:

>>> print(('{}'*len(data)).format(*data))
777777777777777777777777
dansalmo
  • 10,936
  • 5
  • 55
  • 50
  • i got an error from your first example. `>>> print '{}{}{}{}'.format(*[7,7,7,7])` ` File "", line 1` ` print '{}{}{}{}'.format(*[7,7,7,7])` ` ^` `SyntaxError: invalid syntax` `>>> ` – dave campbell Feb 06 '20 at 12:17
  • Do not type the `>>>` part. That is just the prompt for a typical python command line session. – dansalmo Feb 06 '20 at 17:00
  • 1
    i didn't. it's hard to format inline code in comments. the code, as written, does not work. i think the print command in python 3 needs parentheses. i took the "and higher" too literally, i guess. – dave campbell Feb 07 '20 at 22:58
6

You can convert it to a string, and then to an int:

print(int("".join(str(x) for x in [7,7,7,7])))
jh314
  • 25,902
  • 15
  • 60
  • 80
2

Something like this should do it:

for element in list_:
   sys.stdout.write(str(element))
dstromberg
  • 6,698
  • 24
  • 25