是否有一种方法可以迭代列表并根据列表内容更改字符串?



我是一个全新的python,并试图在实践中学习,并开始了我的第一个真正的项目。还不到4小时,我就遇到了一个大问题。我正在尝试配对可能的输入变量,以便我可以使用该输入来引用字典。不知道这是否可能,我也没能通过参考资料弄清楚。如果可能的话,我离你有那么远吗?

yeast_check = ['lalvin', 'zymaflore', 'actiflore', 'redstar', ' ', 'fermemtis', 'lallemand', 'safale', 'bourgoblanc', 'bourgorouge', 'k1','icv', '-']
yeast_input = input('enter yeast type:')
def yeast_convert(yeast_input):
for check in list(yeast_check):
yeast_input = yeast_input.replace(check, '')
return yeast_input
yeast_check = ['lalvin', 'zymaflore', 'actiflore', 'redstar', ' ', 'fermemtis', 'lallemand', 'safale', 'bourgoblanc', 'bourgorouge', 'k1','icv', '-']
yeast_input = input('enter yeast type:')
def yeast_convert(yeast_input):
for check in list(yeast_check):
yeast_input = yeast_input.replace(check, '')
return yeast_input
print(yeast_convert(yeast_input))

尝试在for循环之后调用

最新更新