Search code examples
pythonlistprintingquotessingle-quotes

Python prints single quotes


I have a Python project for uni which I've completed and works fine BUT it keeps printing single quotes like this:

('a', 'b') 0
('a', 'c') 1
('b', 'c') 2
('c', 'd') 0
('d', 'e') 1
('e', 'c') 3

How do I remove them?

Those letters are the names of teams from a file,the combinations are the matches that should be played, I put them into a graph and then I did the rest of the exercise. My only problem is the quotes thing. Thanks in advance!


Solution

  • It looks like you have built a bunch of tuples:

    team1 = 'a'
    team2 = 'b'
    tpl = (team1, team2)
    

    And then printed them:

    print(tpl)
    

    The problem is that you're getting Python's default printout behavior for the tuples. There are a bunch of alternatives for you - defining a class, and then overriding the __str__ method, for example - but what you probably want to do, in order to get things working, is just set up a more complex print command:

    print("{} vs. {}".format(tpl[0], tpl[1]))
    

    or:

    print(tpl[0], "vs.", tpl[1])