I try create class, which will return values to pretty print. I found this post python __str__ for an object but I still can't understand how I can improve my class.
Here is my class:
class PrintList():
def __init__(self,lista):
self.lista=lista
def __str__(self):
if isinstance(x[0] in self.lista, dict): #for dicts in list
return ','.join(str(item),'->',str(item[x]) for x in item) for item in self.lista
else: # for variables in list
return ','.join(str(x) for x in self.lista)
and bug in first return:
return ','.join(str(item),'->',str(item[x]) for x in item) for item in self.lista
^
SyntaxError: invalid syntax
I try get the following result: key_dict->value_dict, etc.