Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to print a list with integers without the brackets, commas and no quotes? [duplicate]

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?

like image 328
Doug Avatar asked Jul 20 '13 00:07

Doug


People also ask

How do you print a list without brackets or commas?

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.

How do I remove brackets when printing a list?

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.

How do you print all elements in a Python list without brackets?

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(', '.


1 Answers

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)) 
like image 168
Jon Clements Avatar answered Sep 29 '22 00:09

Jon Clements