我想知道是否有人可以提供帮助,所以当用户输入“英语”,“西班牙语”或“两者”时,它会打印出没有括号和语音标记的列表,我只需要逗号。我尝试环顾四周,但是没有任何代码有效。任何帮助将非常感激。
english_list = ["fire","apple","morning","river"]
spanish_list = ["fuego","manzana","manana","rio"]
english_to_spanish = dict(zip(english_list, spanish_list))
spanish_to_english = dict(zip(spanish_list, english_list))
def viewwordlist():
if word == 'show':
wordlist = input("""
Type 'English' to view the English word list
Type 'Spanish' to view the Spanish word list
Type 'Both' to view both of the word lists
""").lower().strip()
if wordlist == 'english':
print("Here is the current English word list:")
print(english_list)
elif wordlist == 'spanish':
print("Here is the current Spanish word list:")
print(spanish_list)
elif wordlist == 'both':
print("Here is both the current English and Spanish word list:")
print("Current English list:")
print(english_list)
print("Current Spanish list:")
print(spanish_list)
else:
print("Sorry, that wasn't a option. If you need some assistance please enter 'help'")
english_list = ["fire","apple","morning","river"]
如果您只是print
一个list
Python,它将使用单引号和方括号,因为这是它使用的语法。
>>> print english_list
['fire', 'apple', 'morning', 'river']
如果只想用逗号分隔单词,则可以使用快速join
表达
>>> print ', '.join(english_list)
fire, apple, morning, river
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句