How to convert a list into a string and convert it to python?


I want to send a list through UDP/TCP, but since they support string list only, I need to convert the list into string and convert it back.

My list is like


I know I can use

string_ = ''.join(list_)

to convert it into string.

But how to convert it back?

Or there is another way I can use UDP/TCP to send a list?

Custom format would depend on the assumptions about the list items format, so json looks like the safest way to go:

>>> import json
>>> data = json.dumps(['S1','S2','H1','C1','D8'])
>>> data
'["S1", "S2", "H1", "C1", "D8"]'
>>> json.loads(data)
[u'S1', u'S2', u'H1', u'C1', u'D8']