目前,我的数据位于目录
中myDict = {'a':'Andy','b':'Bill','c':'Carly' }
我希望实现像
这样的东西input = a --> output = Andy
input = ab --> output = Andy Bill
input = abc --> output = Andy Bill Carly
我该怎么做?请帮帮我
答案 0 :(得分:1)
你能处理这些功能吗?如果没有,请发布您的最佳尝试和问题描述。
答案 1 :(得分:1)
isim
不是函数,您需要做的就是在字典中访问该键
def girdi_al():
isim = input("isim giriniz: ")
return isim
def isim_donustur(isim):
cikti = isim
donusum = {'a':'Ankara','b':'Bursa','c':'Ceyhan'}
#How can I do?
result = []
for letter in cikti:
result.append(donusum[cikti])
print(' '.join(result))
def main():
isim_donustur(girdi_al)
# === main ===
main()
答案 2 :(得分:1)
def girdi_al():
isim = input("isim giriniz: ")
return isim
def isim_donustur(isim):
cikti = isim()
donusum = {'a':'Ankara','b':'Bursa','c':'Ceyhan'}
string = ''
for char in cikti:
string += donusum[char] + ' '
print(string )
def main():
isim_donustur(girdi_al)
# === main ===
main()
答案 3 :(得分:0)
像这样的事情
myDict = {'a':'Andy','b':'Bill','c':'Carly' }
input_str = "abc"
" ".join([v for k,v in myDict.items() if k in list(input_str)])