How to join list in Python but make the last separator different?

"&".join([",".join(my_list[:-1]),my_list[-1]])

I would think would work

or maybe just

",".join(my_list[:-1]) +"&"+my_list[-1]

to handle edge cases where only 2 items you could

"&".join([",".join(my_list[:-1]),my_list[-1]] if len(my_list) > 2 else my_list)

Leave a Comment