Usage of the Set module in Python

Source: Internet
Author: User

Today there is a simple small need: to find the number of each element in the list, there are several ways to implement it, here I say a set to achieve.

#!/usr/bin/env PYTHONFA = [1,2,3,4,5,3,2,1,1,1,1,1,1,3,3,3,3,3]FB = set (FA) for I in Fb:print i,fa.count (i)

A list is defined first, then the list is assigned to the FB after using set initialization, in the For loop FP, the value of the FP is in the list, and after the values in the list are obtained, the Count function is used to calculate the number of each value.

Personally feel very good, there is not the place everyone points out, to communicate together.

This article comes from "My future is not a dream." "Blog, be sure to keep this provenance http://song49.blog.51cto.com/4480450/1543498

Usage of the Set module in Python

Related Article

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.