Python Forum
How to transform an enumerate object into a dictionary
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to transform an enumerate object into a dictionary
#5
I'm confused. What are we trying to do?
You can make a dictionary directly from an enumerated string:
>>> d = dict(enumerate("spam and eggs"))
>>> d
{0: 's', 1: 'p', 2: 'a', 3: 'm', 4: ' ', 5: 'a', 6: 'n', 7: 'd', 8: ' ', 9: 'e', 10: 'g', 11: 'g', 12: 's'}
>>>
Reply


Messages In This Thread
RE: How to transform an enumerate object into a dictionary - by Mekire - Jan-29-2018, 12:20 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Alternative of this mini code without Enumerate and join function. Ace4Benji 2 2,541 Mar-09-2020, 08:22 PM
Last Post: micseydel
  Code Review: Range and Enumerate lummers 2 2,175 Jan-11-2020, 12:40 AM
Last Post: lummers
  Help using a pre-code for Discrete Fourier Transform ToucheP 0 1,712 Mar-28-2019, 06:18 AM
Last Post: ToucheP
  enumerate and output control atux_null 7 5,268 Oct-24-2017, 06:50 PM
Last Post: Mekire

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020