내림차순으로 나는 코드의이 비트가파이썬 정렬 Collections.DefaultDict 위해
sorted(visits.iteritems, key=operator.itemgetter(1), reverse=True)
을하지만, 나에게주는거야 :
"TypeError: 'builtin_function_or_method' object is not iterable"
이유가 확실하지 않습니다.
내림차순으로 나는 코드의이 비트가파이썬 정렬 Collections.DefaultDict 위해
sorted(visits.iteritems, key=operator.itemgetter(1), reverse=True)
을하지만, 나에게주는거야 :
"TypeError: 'builtin_function_or_method' object is not iterable"
이유가 확실하지 않습니다.
iteritems는 방법입니다. 호출하려면 괄호가 필요합니다 (visits.iteritems()
).
iteritems 메서드 자체를 sorted
에 전달하면 함수 또는 메서드를 반복 할 수 없다는 불만이 생깁니다.
개인적으로 나는 첫 번째 인수가 반복기가 아닌 반복 가능해야하기 때문에 이러한 형식 중 하나는 좀 더 간결하다고 생각합니다.
키가 아닌 값을 정렬하고 싶습니다. – miles82
정확합니다. 질문을 잘못 읽었습니다. – mattkemp