Post

PythonPython

p
persis crystal

Posted on 3rd March 2024|34 views

0
votes

Python Enumerate Dictionary

How can I create a python dictionary by enumerate function?

Answers
P
sumana reddy

Posted on 3rd March 2024

Here is the example

>>> li1=['xx','yy','zz']

>>> enum=enumerate(li1)

>>> enum

>>> di=dict((p,q) for p,q in enum)

>>> di

{0: 'xx', 1: 'yy', 2: 'zz'}

 

Write your answer

STILL GOT QUERIES?

Get a Live FREE Demo
  • Explore the trending and niche courses and learning maps
  • Learn about tuition fee, payment plans, and scholarships
  • Get access to webinars and self-paced learning videos