38

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
  • 377,200
  • 20
  • 156
  • 213
Doug
  • 429
  • 1
  • 4
  • 8

5 Answers5

85

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
  • 138,671
  • 33
  • 247
  • 280
15

Try this:

print("".join(str(x) for x in This))
zwol
  • 135,547
  • 38
  • 252
  • 361
10

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
  • 11,506
  • 5
  • 58
  • 53
  • 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
8

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
  • 27,144
  • 16
  • 62
  • 82
2

Something like this should do it:

for element in list_:
   sys.stdout.write(str(element))
dstromberg
  • 6,954
  • 1
  • 26
  • 27