python - 'method' object is not subscriptable. Don't know what's wrong -


i'm writing code create unsorted list whenever try insert list using insert method 'method' object not subscriptable error. not sure how fix it. thanks.

class unsortedlist:     def __init__(self):         self.thelist = list()     def __getitem__(self, i):        print(self.thelist[i])     def insert(self, lst):         x in lst:             try:                 self.thelist.append(float(x))             except:                 print("oops")   mylist = unsortedlist() mylist.insert[1, 2, 3] 

you need use parentheses: mylist.insert([1, 2, 3]). when leave out parentheses, python thinks trying access mylist.insert @ position 1, 2, 3, because that's brackets used when right next variable.


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -