- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to create Python dictionary by enumerate function?
Python enumerate() function takes any iterable as argument and returns enumerate object using which the iterable can be traversed. It contains index and corresponding item in the iterable object like list, tuple, or string.
Such enumerate object with index and value is then converted to a dictionary using dictionary comprehension.
>>> l1=['aa','bb','cc','dd'] >>> enum=enumerate(l1) >>> enum >>> d=dict((i,j) for i,j in enum) >>> d {0: 'aa', 1: 'bb', 2: 'cc', 3: 'dd'}
Learn Python with our step-by-step Python Tutorial.
Advertisements