I have this bit of code:
visits = defaultdict(int) for t in tweetsSQL: visits[t.user.from_user] += 1
I looked at some examples online that used the sorted method like so:
sorted(visits.iteritems, key=operator.itemgetter(1), reverse=True)
but it is giving me:
'TypeError: 'builtin_function_or_method' object is not iterable'
I am not sure why.
iteritems is a method. You need parenthesis to call it:
visits.iteritems().As it stands now, you are passing the iteritems method itself to
sortedwhich is why it is complaining that it can’t iterate over a function or method.