2014-10-06 85 views
0

我想知道当用户输入“英文”,“西班牙文”或“两者”时是否有人可以提供帮助,它打印出没有括号和语音标记的列表,我只想要逗号。我试过四处寻找,但没有为我的代码工作。任何帮助将非常感激。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'") 
+1

而不是描述bing你想要的输出,向我们展示确切的期望样本输出。 – abarnert 2014-10-06 22:49:54

回答

3
english_list = ["fire","apple","morning","river"] 

如果你只是一个print Python的list将包括单引号和方括号,因为那是语法,它使用。

>>> print english_list 
['fire', 'apple', 'morning', 'river'] 

如果你只是想用逗号分隔的话,你可以使用一个快速join表达

>>> print ', '.join(english_list) 
fire, apple, morning, river 
+0

哦......呃。谢谢!削减我一些松懈,我刚从工作回来:) – CoryKramer 2014-10-06 22:51:36

+0

考虑松弛已被削减:-) – mgilson 2014-10-06 22:52:06

+0

嗨,感谢您的答复,但我得到一个语法错误时,我把代码中。你知道为什么那是?谢谢 – 2014-10-06 23:04:33

2

使用join

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

使用加入:

print ', '.join(english_list)