-2

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?

chash
  • 3,975
  • 13
  • 29
  • Welcome to StackOverflow. Please take the [tour] and read [ask]. Also be sure to search for existing answers (like [concatenate item in list to strings](https://stackoverflow.com/questions/12453580/concatenate-item-in-list-to-strings)) before posting a new question. – chash Jul 09 '20 at 23:14

2 Answers2

1

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.

alan.elkin
  • 954
  • 1
  • 10
  • 19
0

you may use the join()

list = ['a', 'b', 'c', 'd', 'e', 'f']
' -> '.join(list)