Point a favor and leave a note !!
list :list read-write repeatable Store as value Orderly initial ['a',1] How to add append
Tuples :tuple Read only repeatable Store as value Orderly initial ('a',1) Cannot add
Dictionaries : dict read-write repeatable Key pair value ( Key is not repeatable ) disorder initial {‘a’:1,'b':2} add to c['key']='value'
Catalog
One 、 list 、 Dictionaries 、 character string ----> Turn a tuple
Two 、 Dictionaries 、 Tuples 、 character string ----> To list
3、 ... and 、 list 、 Tuples 、 Dictionaries ----> Turn the string
Four 、 character string ----> Turn Dictionary , and key And value Interturn
# List transfer --> Tuples
print(tuple([' Zhang San ',' Li Si '])) # (' Zhang San ', ' Li Si ')
print(tuple(eval("[' Zhang San ',' Li Si ']"))) # (' Zhang San ', ' Li Si ')
# Dictionary transfer --> Tuples
print(tuple({' Zhang San ',' Li Si '})) # (' Zhang San ', ' Li Si ')
print(tuple(eval("{' Zhang San ',' Li Si '}"))) # (' Zhang San ', ' Li Si ')
dict_list = {' Zhang San ':30,' Li Si ':90}
print(tuple(dict_list.values())) # (30, 90)
print(tuple(dict_list)) # (' Zhang San ', ' Li Si ')
# String rotation --> Tuples
print(tuple('abcd')) # ('a', 'b', 'c', 'd')
# String rotation --> List transfer --> Tuples
list_s = [] # Create an empty list
list_s.append('abcd') # take abcd Write to list
print(tuple(list_s)) # ('abcd',)
# Dictionary transfer --> list
print(list({' Zhang San ',' Li Si '})) # [' Zhang San ', ' Li Si ']
print(list(eval("{' Zhang San ',' Li Si '}"))) # [' Zhang San ', ' Li Si ']
# Turn a tuple --> list
print(list((' Zhang San ',' Li Si '))) # [' Zhang San ', ' Li Si ']
print(list(eval("(' Zhang San ',' Li Si ')"))) # [' Zhang San ', ' Li Si ']
# String rotation --> list
print('hello python'.split(' ')) # ['hello', 'python']
# String rotation --> list
list = [] # Create an empty list
list.append('abcd') # take abcd Write to list
print(list) # ['abcd']
# List transfer --> character string
print(''.join(['a', 'b', 'c', 'd'])) # abcd
# Turn a tuple --> character string
print(''.join(('a', 'b', 'c', 'd'))) # abcd
# Dictionary transfer --> character string
print(str({'a': 1, 'b': 2})) # {'a': 1, 'b': 2}
# Tuples cannot be converted to dictionaries
# List cannot be converted to dictionary
# String rotation --> Dictionaries
print(eval("{'a': 1, 'b': 2}")) # {'a': 1, 'b': 2}
# Dictionaries key and value Value conversion
dic1 = {'a': 1, 'b': 2, 'c': 3}
dic2 = {value: key for key, value in dic1.items()}
print(dic2)