If you need to convert a set
to a string
in Python, then you can do one of the following:
Option 1 – Using map()
and join()
1
|
str_new = ', '.join(list(map(str, se)))
|
You can confirm this worked as follows:
1
2
3
4
5
|
print(str_new)
print(type(str_new))
# '1, 2, 3'
# <class 'str'>
|
Option 2 – Using repr()
You can confirm this worked as follows:
1
2
3
4
5
|
print(r_str)
print(type(r_str))
# {1, 2, 3}
# <class 'str'>
|