在Python上打印没有括号的列表

时间:2014-10-06 22:46:52

标签: python python-3.x

我想知道当用户输入英语时,是否有人可以提供帮助,' '西班牙,'或者'两者都是'它打印出没有括号和语音标记的列表,我只想要逗号。我试着环顾四周,但我的代码没有任何效果。任何帮助将非常感激。

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'")

3 个答案:

答案 0 :(得分:3)

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

答案 1 :(得分:2)

使用join

>>> english_list = ["fire","apple","morning","river"]
>>> print ",".join(english_list)
fire,apple,morning,river

答案 2 :(得分:0)

使用join:

print ', '.join(english_list)
相关问题