I am having issues with formatting and understand lists and strings when it comes to classes. So I have this code here:
class User:
def __init__(self,title):
self.tile=tile
self.rank={}
def addCard(self,compID,number):
if compID in self.cards and number > self.cards[compID]:
self.cards[compID]=number
elif compID not in self.cards:
self.cards[compID]=number
def __str__(self):
self.cardList = []
for compID, number in self.cards.items():
final = compID + "-" + str(number)
self.cardList.append(temp)
self.cardList.sort()
return self.tile + ":" + " " + "Card scores:" + str(self.cardList)
so my result looks like this:
OUTPUT 1:
Cpt.Fred: Card scores: ['diamond-22', 'hearts-4', 'spades-3']
Lt.Connor: Card scores: ['diamond-43']
I am trying to make my result look like this:
OUTPUT 2:
Cpt.Fred: Card scores: [ diamond-22, hearts-4, spades-3 ]
Lt.Connor: Card scores: [ diamond-43 ]
The data is not whats important, its how to get rid of the " ' " at the beginning and the end of the results. I think it has something to do with my last def() statement but I have been trying to format it every way with no luck. Can anyone help turn the first output to look like the second output?
strvsrepr