[英]Printing lists without brackets on Python
我想知道是否有人可以提供幫助,所以當用戶輸入“英語”,“西班牙語”或“兩者”時,它會打印出沒有括號和語音標記的列表,我只需要逗號。 我嘗試環顧四周,但是沒有任何代碼有效。 任何幫助將非常感激。
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
使用join
>>> english_list = ["fire","apple","morning","river"]
>>> print ",".join(english_list)
fire,apple,morning,river
使用聯接:
print ', '.join(english_list)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.