Python print list without quotes and commas

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?

Python print list without quotes and commas

Ronak Shah

361k19 gold badges131 silver badges187 bronze badges

asked Jul 20, 2013 at 0:34

0

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))

answered Jul 20, 2013 at 0:50

Python print list without quotes and commas

Jon ClementsJon Clements

134k31 gold badges240 silver badges273 bronze badges

2

Try this:

print("".join(str(x) for x in This))

answered Jul 20, 2013 at 0:35

zwolzwol

131k36 gold badges241 silver badges352 bronze badges

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

answered Jul 20, 2013 at 2:15

dansalmodansalmo

11.1k5 gold badges55 silver badges51 bronze badges

3

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

print(int("".join(str(x) for x in [7,7,7,7])))

answered Jul 20, 2013 at 0:44

jh314jh314

26.2k15 gold badges61 silver badges81 bronze badges

6

Something like this should do it:

for element in list_:
   sys.stdout.write(str(element))

answered Jul 20, 2013 at 0:36

dstrombergdstromberg

6,76424 silver badges25 bronze badges

0

In this article, we will figure out four unique methods to print list without brackets and quotes in Python but foremost, what is list?

A list is the data structure in python that allows you to store a collection of items stored in a variable. Lists are mutable or changeable. We can define a list with the following syntax.

apples = ["Fuji", "McIntosh", "Red Delicious", "Gala", "Jonagold"]

print(apples) 

The above line defines the list of different types of apples stored in the “apples” variable. It will give us the output like this:

Python print list without quotes and commas

But what if you want to display it by removing brackets and commas from list? Well, in this article we’re going to discuss different methods to do so.

For Loop is the most general solution that comes first to the mind when you try to solve this problem.  In this, we iterate through each value of a list and print that value.

apples = ["Fuji", "McIntosh", "Red Delicious", "Gala", "Jonagold"]

for apple in apples:

print(apple, end=", ")

print("\b\b", end="")

print(" ") 

Python print list without quotes and commas

  1. First, we declare the list.
  2. Using for loop, we iterate through each value of a list and print that value with a comma and space. (if you only want to add a space between the values of a string then just add a space in the end parameter and skip the next steps).
  3. The for loop also added a comma and space at last so to remove this we move over the cursor to the last two printed items.
  4. Furthermore, at the last step, we move the comma with space.

Using join() method:

There is a built-in method in python called join(). It takes an iterable and converts it into a string with the specified value given with it.

apples = ["Fuji", "McIntosh", "Red Delicious", "Gala", "Jonagold"]
separator = ", "
print(separator.join(apples)) 

Python print list without quotes and commas

You can define that value in the separator variable through which you want to join the items in the list.

One thing to remember that if you want to join the integer values, then the join method will not work because it is a string method. It will generate the following error.

Even_no = [2, 4, 6, 8]
   separator = ", "
   print(separator.join(Even_no))
 

Python print list without quotes and commas

But, if you want to use join function for print list without brackets and commas, then you can accomplish this by using map() function.

Even_no = [2, 4, 6, 8]
   separator = ", "
   print(separator.join(map(str, Even_no))) 

Python print list without quotes and commas

The map() function takes two argument, first is a function and second is a item from iterable which need to be mapped and it passes to that function which is mention is the first argument.

The map() function returns an iterable which is now converted into a string and then it passes to the join() method.

Using sep keyword in print:

Separator, written as “sep” is a keyword which is used in a print statement when you want to separate two different values or objects in a print statement with a specific string.

apples = ["Fuji", "McIntosh", "Red Delicious", "Gala", "Jonagold"]
   print(*apples, sep=", ") 

Python print list without quotes and commas

* written in front of apples causes apples to be unpacked in items and converted into a string, then these items are combined with value which is specified in the sep keyword.

If you just want to separate the items and print a list without the brackets and single quotes, then you don’t need to specify the value of sep because it has a default value of whitespace.

Using translate() method:

The translate() is a string method which will change the string by replacing or deleting the characters.

apples = ["Fuji", "McIntosh", "Red Delicious", "Gala", "Jonagold"]
   target = {39 : None, 91 : None, 93 : None}
   print(str(apples).translate(target))
 

Python print list without quotes and commas

We specific the changes which we want in our string in the “target” variable, where 39, 91, and 93 are the ASCII codes for “,” , “[“ and “]” respectively. We set these characters to none and translate our list by converting it into a string because translate is a string method.

Conclusion:

There could be uncommon scenarios when you want to print list without brackets and quotes in Python. In this article, we’ve discussed four distinct methods using different python functions.

How do you print a list without commas and quotes in Python?

Method 2: Print List Without Quotes and Commas. To print a string list without quotes and commas, use the expression '[' + ' '. join(lst) + ']' to create a single string representation of the list without the quotes around the individual strings and without the commas separating the list elements.

How do you print a string list without quotes in Python?

Here are some ways to print lists/strings without the use of quotes..
1.Using map() method to Print without quotes in python..
Using sep() method To Print Without Quotes In Python..
Using .format() method To Print Without Quotes In Python..
Using translate method To Print Without Quotes In Python..

How do you remove quotes from a list in Python?

To remove the quotes from a list of strings:.
Use a list comprehension to iterate over the list..
Use the str. strip() method to remove the leading and trailing quotes from each string..
The items in the new list won't contain leading and trailing quotes..

How do you print a string without commas in Python?

To print a list without the commas and brackets:.
Use the str. join() method to join the list into a string..
If the list contains numbers, convert them to strings..
Use the print() function to print the string..