Reputation: 21
I was wondering if someone could help so when the user enters in 'English,' 'Spanish,' or 'Both' It prints out the list without the brackets and speech marks, I only want commas. I tried looking around but nothing worked for my code. Any help would be much appreciated.
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'")
Upvotes: 0
Views: 752
Reputation: 19776
use join
>>> english_list = ["fire","apple","morning","river"]
>>> print ",".join(english_list)
fire,apple,morning,river
Upvotes: 2
Reputation: 117876
english_list = ["fire","apple","morning","river"]
If you just print
a list
Python will include the apostrophes and square braces, because that is the syntax it uses.
>>> print english_list
['fire', 'apple', 'morning', 'river']
If you just want the words delimited by a comma, you can use a quick join
expression
>>> print ', '.join(english_list)
fire, apple, morning, river
Upvotes: 3