I think we can--python the new __python

Source: Internet
Author: User

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.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.