0

Given the following list:

l1=[1,2,3,4]

I would like to print out the following numbers without brackets,

1,2,3,4

without converting them to strings and without using for loop.

Is there a way in python to accomplish that?

All my searches lead to either string conversion or generation of another list including brackets.

Gino Mempin
  • 25,369
  • 29
  • 96
  • 135
d8a988
  • 71
  • 1
  • 2
  • 10
  • 2
    Does this answer your question? [Print list without brackets in a single row](https://stackoverflow.com/questions/11178061/print-list-without-brackets-in-a-single-row) (specifically this answer https://stackoverflow.com/a/35119046/2745495 which should satisfy all your restrictions) – Gino Mempin Jul 09 '21 at 00:04

1 Answers1

0

Try:

l1 = [1, 2, 3, 4]

print(*l1, sep=",")

Prints:

1,2,3,4
Andrej Kesely
  • 168,389
  • 15
  • 48
  • 91
  • `a = *l1, sep="," print(type(a)) ` which will make a string, But it is a good solution – Abhi Jul 08 '21 at 12:40
  • abhi: it must not be a string – d8a988 Jul 08 '21 at 12:46
  • andrej kesely: your code snippet works perfectly if is left untouched, however it presents an invalid syntax error as soon as I apply a small modification. e.g. a=(*l1, sep=","), print(a). Is there a way to assign a variable like I did without running into an error? – d8a988 Jul 08 '21 at 12:55