-2

I just started learning python, and I am just trying to use the join function to combine a list to a string, but I keep getting this error

store_str = (',').join(store_hours)
  TypeError: sequence item 0: expected string, int found

Here is my code

time = 15

store_open = None
store_hours = [9, 10, 11, 12, 13, 14, 15, 16, 17, 18]
store_str = (',').join(store_hours)
martineau
  • 119,623
  • 25
  • 170
  • 301
perryfanfan
  • 161
  • 3
  • 10

1 Answers1

4

The exception is raised since integers are sent to the function instead of strings:

store_hours = [9, 10, 11, 12, 13, 14, 15, 16, 17, 18]
store_str = ','.join(map(str, store_hours))

In order to make call str.join the arguments need to be converted to strings first.

Elisha
  • 23,310
  • 6
  • 60
  • 75