1792/how-to-print-array-list-without-brackets-in-python
I want to print a list in python without the square brackets. It is always coming printing like [“a”,”b”,”c”]
Announcement! Career Guide 2019 is out now. Explore careers to become an AI/ ML Engineer or Data Scientist!
name=["a","b","c"] print (', '.join(name))
It will simply take all the elements in a list(name), and joins them with ‘, ’
Because join() is a method of a string type object, and joins lists that are made of string type objects. If your list is consisted of integers, it would not work. For example, you would have to do str() on all elements of your list to do a join() on it.
print (','.join(name_of_list))
You can try this for arrays:
print str(names)[1:-1]
print(*names, sep = ', ')
This is what I use
You can use looping to do this. This is not the best way but it is a possible way so I posted it:
for name in names: print(names[index], end=", ") index += 1
print(", ".join(str(x) for x in name))
print list without bracket
list = ["Rajesh", "Raj", "Amit", "Neha", "Annu"] print(*list, sep=", ")
output:
Rajesh,Raj,Amit,Neha,Annu
Can you tell what is * for ?
Hey,
If you want to print the elements of the list or array without using loops, then you can use the '*' symbol to print the list elements in a single line with space.
Hey, @There,
Could you please post all your error logs? Please post your workaround.
You can read array from the users like this:
array=list(map(int,input().split()))
And you can directly print the array as follows:
print(array)
There are many other ways to read and write an array. Do you want any particular way to do this?
Call print(*value, sep=" ") with value as a list to unpack and print the elements of the list seperated by the zero or many characters contained in sep. To seperate each element with a comma followed by a space, set sep to ", ".
a_list = ["a", "b", "c"]
print(*a_list, sep = ", ")
OUTPUT
a, b, c
Hey @abhijmr.143, you can print array integers ...READ MORE
ou are using Python 2.x syntax with ...READ MORE
Hi@akhtar, You need to import the NumPy module ...READ MORE
Python doesn't have a native array data ...READ MORE
suppose you have a string with a ...READ MORE
You can also use the random library's ...READ MORE
Syntax : list. count(value) Code: colors = ['red', 'green', ...READ MORE
Enumerate() method adds a counter to an ...READ MORE
You can use '\n' for a next ...READ MORE
calculate square root in python >>> import math ...READ MORE
OR
At least 1 upper-case and 1 lower-case letter
Minimum 8 characters and Maximum 50 characters
Already have an account? Sign in.