I would like to write a custom list class in Python (let\'s call it MyCollection) where I can eventually call:
MyCollection
for x in myCollectionInstance:
You could extend the list class:
list
class MyList(list): def __init__(self, *args): super(MyList, self).__init__(args[0]) # Do something with the other args (and potentially kwars)
Example usage:
a = MyList((1,2,3), 35, 22) print(a) for x in a: print(x)
Expected output:
[1, 2, 3] 1 2 3