I have a list of tuples that consist of objects of a certain class and differ in their dimension:
my_list = [(obj1, obj2), (obj3, obj1), (obj4, obj1), (obj2,),...]
All of these objects have an attribute label
which is of type string
and holds an object label e.g. 'object_1'
, 'object_2'
and so on.
Now I want to extract the string representation of the tuples holding the attribute values (labels) e.g.:
my_new_list = ['(object_1, object_2)', '(object_3, object_1)', '(object_4, object_1)', '(object_2,)', ...]
I have looked up how to extract a list of attributes from a list of objects and how to convert a tuple to string and would probably achieve my goal with some nested for loops. But I got stuck in some messy code here..
But isn't there some nice pythonic way to do this?
Thanks in advance!
*EDIT: Some of the tuples are one dimensional e.g. (obj2,)
. Sorry, I forgot that and now have adapted my question!