SoFunction
Updated on 2024-11-18

python-str,list,set conversion example

Examples are as follows:

a = '123abbcc!@#' 
b = ['1', '2', '3', 'a', 'b', 'c', '!', '@', '#']
c = set(['a', '!', 'c', 'b', '@', '#', '1', '3', '2']) 

str -> list:list(a) 
result : ['1', '2', '3', 'a', 'b','b', 'c','c','!', '@', '#']
list -> str : ''.join(list) 
result : 123abc!@#

str -> set : set(a)
result : set(['a', '!', 'c', 'b', '@', '#', '1', '3', '2']) set types are unordered non-repeating
set -> str :  ''.join(c) 
result: a!cb@#132

set -> list : list(c)
result : ['a', '!', 'c', 'b', '@', '#', '1', '3', '2']
list -> set : set(b)
result : set(['a', '!', 'c', 'b', '@', '#', '1', '3', '2'])

The above example of this python-str,list,set conversion between is all I have shared with you, I hope to give you a reference, and I hope you support me more.