When I was a child, I thought about the features in my world: get all the videos up and count the top candidates. Feel good and complete.
Now, I'm still a child, but my brain is getting bigger.
Recently reading met a lot of Coolcool library, looking back at the code at that time, miserable AH
Def author_get (): All
= videodoc.objects ()
authors = [] for a in all
:
authors.append (A.author)
Count = 1
l = len (authors)-1
x = {}
t = 0 while
t <= l:
th = authors[t]
i = t + 1
while I <= L:
if th = authors[i]:
count + + 1
del authors[i]
i-= 1 L-
= 1
i + 1
x[th] = Count
count = 1
t + + 1
y = sorted (X.iteritems (), Key=lambda x:x[1], reverse=true)
ten = (y[1), y[2], Y[3], y[4], y[5], y[6], y[7], y[8], y[9], y[10] return
Ten
Now, I can use three lines of code to complete the above features
From collections Import Counter
authors = [V.author to V in Videodoc.objects ()]
hot_author = Counter (authors). Mo St_common (10)
I felt so flattered when I saw it.
Sugar, just help me remember.