Is there a better code to comma all the strings on the list? (['a','b'] -> "a,b")

Asked 2 years ago, Updated 2 years ago, 86 views

I'm going to attach the entire list element as a string to distinguish each element

['a','b'] -> "a,b"

I'm going to add a comma like this.

Usually, I

''.join(map(lambda x: x+',',l))[:-1]

I wrote it like this, but I wonder if there is any other way.

android-listview python

2022-09-22 22:13

1 Answers

Even if you don't use Lambda

myList = ['a','b','c','d']
myString = ",".join(myList)

You can write. If the list stores numbers, there will be an error, so please add a code that converts the type separately

myList = ','.join(map(str, myList)) 


2022-09-22 22:13

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.