1. Dictionaries
Dictionary to String
>>> dict={' name ': ' Zhzhgo ', ' Age ':25}>>> print type (str (dict)), str (dict) <type ' str ' > {' age ': ' Name ': ' Zhzhgo '}>>>
Dictionary conversion to tuples
>>> dict={' name ': ' Zhzhgo ', ' Age ':25}>>> print type (tuple (dict)), tuple (dict) <type ' tuple ' > (' Age ', ' name ') >>>
Dictionary to List
>>> dict={' name ': ' Zhzhgo ', ' Age ':25}>>> Print type (list (dict)), List (dict) <type ' list ' > [' Age ' ', ' name ']>>>
2, meta-group
Tuples converted to strings
>>> mytupe= >>> Print mytupe.__str__ () (1, 2, 3) >>> >>> mylist= (' h ', ' e ', ' l ', ' l ', ' o ') >>> print '. Join (MyList) hello>>>
Tuples to List
>>> mytupe= (mytupe) >>> Print List [1, 2, 3]>>>
Tuples cannot be converted to dictionaries
3. List
List to String
>>> mylist=[' h ', ' e ', ' l ', ' l ', ' O ']>>> print '. Join (MyList) hello>>>
List to tuple
>>> mylist=[1,2,3]>>> Print Tuple (mylist) (1, 2, 3) >>>
List cannot be converted to dictionary
4. String
Convert string to tuple
>>> mystring= "Hello" >>> print tuple (mystring) (' H ', ' e ', ' l ', ' l ', ' o ') >>>
String to List
>>> mystring= "Hello" >>> Print List (mystring) [' H ', ' e ', ' l ', ' l ', ' O ']>>>
String to Dictionary
>>> mystring= "{' name ': ' Zhzhgo ', ' age ': +} ' >>> print type (eval (mystring)) <type ' Dict ' >> >>
This article from "Today's efforts, tomorrow's success!" "Blog, be sure to keep this provenance http://zhzhgo.blog.51cto.com/10497096/1671868
Conversions between arrays, tuples, dictionaries, and strings in Python