Print list without brackets in a single row
print(', '.join(names))
This, like it sounds, just takes all the elements of the list and joins them with ', '
.
Print List elements in loop without Brackets and Quote marks
You probably just need to access the zero'th element of the numpy array Title
like you did in the first part of the code.
See you did this in the first part:
print('Recipe Recommendations for: {0}'.format(Title[0]))
so do this in the second part:
print(Title[0], "With Distance of ", Distance)
How to remove square brackets from list in Python?
You could convert it to a string instead of printing the list directly:
print(", ".join(LIST))
If the elements in the list aren't strings, you can convert them to string using either repr
(if you want quotes around strings) or str
(if you don't), like so:
LIST = [1, "foo", 3.5, { "hello": "bye" }]
print( ", ".join( repr(e) for e in LIST ) )
Which gives the output:
1, 'foo', 3.5, {'hello': 'bye'}
Joining multiple lists in a single row, without brackets or quotation marks
Just add the lists:
print('Blahblah %s' % (a + b))
Or use:
print('Blahblah %s' % [*a, *b])
howto print list without brackets and comma python
To print any list in python without spaces, commas and brackets simply do
print(*list_name,sep='')
Python - Print contents of list and include square brackets but not apostrophes
If you are using print(interactive_options)
- you get the result of str(interactive_options)
:
>>> print(interactive_options)
['list', 'heroes', 'villains', 'search', 'reset', 'add', 'remove', 'high', 'battle', 'health', 'quit']
>>> str(interactive_options)
['list', 'heroes', 'villains', 'search', 'reset', 'add', 'remove', 'high', 'battle', 'health', 'quit']
However, you can use join
(which returns a string by joining all the elements of an iterable (list, string, tuple), separated by a string separator) to format the output as you wish, like so:
>>> ", ".join(interactive_options)
list, heroes, villains, search, reset, add, remove, high, battle, health, quit
You can add then the brackets and colon to the output:
>>> interactive_options_print = ", ".join(interactive_options)
>>> interactive_options_print = "[" + interactive_options_print + "]:"
>>> interactive_options_print
[list, heroes, villains, search, reset, add, remove, high, battle, health, quit]:
Related Topics
How to Run Celery Workers by Superuser
Serving a Request from Gunicorn
Python For-In Loop Preceded by a Variable
What Are the Risks of Running 'Sudo Pip'
Pg_Config Executable Not Found
Why Can't I Use a List as a Dict Key in Python
Weird Timezone Issue with Pytz
What Is the Use of "Assert" in Python
How to Embed Matplotlib in Pyqt - for Dummies
No Module Named 'Virtualenvwrapper'
Differencebetween Size and Count in Pandas
Apply Function to Each Element of a List
How to Return Dictionary Keys as a List in Python
Convert Pyspark String to Date Format
How to Print the Value of a Tensor Object in Tensorflow
Why Does Adding a Trailing Comma After a Variable Name Make It a Tuple