I have a list of single character strings:
list = ['a', 'b', 'c', 'd', 'e', 'f']
I need to print the items in the list, separated with ->
like so:
a -> b -> c -> d -> e -> f
How can I do it?
I have a list of single character strings:
list = ['a', 'b', 'c', 'd', 'e', 'f']
I need to print the items in the list, separated with ->
like so:
a -> b -> c -> d -> e -> f
How can I do it?
You could use the parameter sep
of the built-in print
function (see the docs), alongside with the list unpacking operator *
.
For your case:
my_list = ['a', 'b', 'c', 'd', 'e', 'f']
print(*my_list, sep=' -> ')
Note that I replaced list
variable name with my_list
. It is highly recommended to avoid shadowing names, specifically built-in names like list
.
you may use the join()
list = ['a', 'b', 'c', 'd', 'e', 'f']
' -> '.join(list)