问题描述:
解题思路:
class Solution:
def twoSum(self, shuru: str, shuru1: str) :
#逗号分离 user_lie = shuru.split(',')
#自定义两个字典,用:分离生产原始字典 usr = {}
#用l存储数据 l = {}
for i in range(len(user_lie)):
j = user_lie[i].split(':')
usr = {j[0]: j[1]}
# print(usr) l.update(usr)
#定义结果字符串 fanhui = ''
j = []
#列表遍历 for m, n in l.items():
if n == shuru1:
fanhui = str(m)
j.append(fanhui)
s = ''
#添加结果要求的逗号分隔符 for o in j:
s += o + ','
if fanhui!='':
return s[:-1]
if fanhui=='':
return 'NONE'
if __name__=="__main__":
solution=Solution()
#按要求输入参数,两个参数 shuru = input("shuru:")
#shuru = 'jimi:199,tim:688,jimiu:1888,wo:1888' shuru1 = input("chazhaozhi:")
print(solution.twoSum(shuru,shuru1))
运行结果: