############################
#!/usr/bin/env python
#-*-coding:utf-8-*-
# python 2.7.0
li = ["Alec", "Aric", "Alex", "Tony", "Rain"]
print (LI)
for I in range (Len (LI)):
li[i] = li[i].replace (', ')
print (li)
tu = ("Alec", "Aric", "Ale X "," Tony "," Rain ")
print (tu)
tu = List (tu) for
T in range (Len (TU)):
tu[t] = Tu[t].replace (", ") C13/>tu = Tuple (TU)
print (TU)
dic = {' K1 ': ' Alex ', ' K2 ': ' Aric ', ' K3 ': "Alex", "K4": "Tony"}
print (d IC) for
k,v in Dic.items ():
dic[k] = Dic[k].replace (",") # for
D in range (Len (DIC)):
# Dic[d ] = Dic[d].replac (', ')
print (DIC)
-------------------------------------------------------------------------------------
< reprint >python A method for converting strings, tuples, lists, and dictionaries into one another
#-*-coding:utf-8-*-
#1, dictionary
dict = {' name ': ' Zara ', ' age ': 7, ' class ': '
a ' #字典转为字符串, return: <type ' str ' > {' age ': 7, ' name ': ' Zara ', ' class ': ' Dict ' (
str), str (dict)
#字典可以转为元组, return: (' age ', ' name ', ' class ')
print tuple (dict)
#字典可以转为元组, returns: (7, ' Zara ', ' the ', ')
print tuple (dict.values ())
#字典转为列表, Back: [' age ', ' name ', ' class ']
Print List (dict)
#字典转为列表
print dict.values
#2, tuple
tup= (1, 2, 3, 4 , 5)
#元组转为字符串, return: (1, 2, 3, 4, 5)
print tup.__str__ ()
#元组转为列表, return: [1, 2, 3, 4, 5]
Print List (tup)
#元组不可以转为字典
#3, List
nums=[1, 3, 5, 7, 8, A;
#列表转为字符串, return: [1, 3, 5, 7, 8,
nums] Print str (
nums) #列表转为元组, return: (1, 3, 5, 7, 8, m)
print tuple (
#列表不可以转为字典
#4, String
#字符串转为元组, returns: (1, 2, 3)
print tuple (eval (1,2,3))
#字符串转为列表, return: [1, 2, 3]
Print List (eval (1,2,3))
#字符串转为字典, returns: <type ' Dict ' >
print Type (eval ("{' name '): ' Ljq ', ' age ' : 24} "))