Python Basic-enumerate function

Source: Internet
Author: User

Application scenario: Sometimes the data output, need to sequence subscript, in terms of others to choose.

Example:

dict1={' mac ': 7000, ' coffe ': +, ' banana ': 5}print (' What does you want to buy?: ') for index,i in Enumerate (Dict1.keys ( ): Print (Index,i)

The enumerate () function requires 2 parameters, a sequence of output files. A data type that the output can traverse.

One of the sequences that can be made as a user's choice. The keys can be converted to a list when the dictionary is taken, and the keys value of the corresponding list is obtained by the user's selection sequence, then the value of the corresponding dictionary is taken. This can be used in multi-level menus.


Python Basic-enumerate function

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.