that_bitch
that_bitch

Reputation: 21

How do I prevent the parens and quotations being printed when printing elements from a list?

def winners(finish_order, teams):
    return finish_order[0], 'and', teams[finish_order[0]], 'won the race!'

print(winners(['Green', 'Zelda', 'Frog'], {'Zelda':'Midna', 'Frog':'Frogette', 'Green':'Red'}))

So running the code above prints ('Green', 'and', 'Red', 'won the race!'). How do I print Green and Red won the race! instead? Basically, I want to print elements from the list without the extra parentheses and quotations, when using them in a sentence.

Upvotes: 1

Views: 30

Answers (1)

Andrej Kesely
Andrej Kesely

Reputation: 195603

Return formatted string, not tuple:

def winners(finish_order, teams):
    return '{} and {} won the race!'.format(finish_order[0], teams[finish_order[0]])

print(winners(['Green', 'Zelda', 'Frog'], {'Zelda':'Midna', 'Frog':'Frogette', 'Green':'Red'}))

Prints:

Green and Red won the race!

Upvotes: 1

Related Questions