Add A Method To A List Instance In Python
I want to add a method to a single instance of the 'list' class. Example: a = [1,2] a.first = lambda self: return self[0] I know this don't work, but I want something like that wo
Solution 1:
Nothing will work with a native list, since you cannot add methods to a type defined in C. You will need to derive from list
and add your method to that class.
Post a Comment for "Add A Method To A List Instance In Python"