Python Forum
Converting '1a2b3c' string to Dictionary
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Converting '1a2b3c' string to Dictionary
#7
Using the same iterator to extract both items for each tuple is brilliant. It is not immediately obvious though. It took a minute for me to understand how it worked,
def todict(kvstring):
    i = iter(kvstring)
    return dict(zip(i, i))
Reply


Messages In This Thread
RE: Converting '1a2b3c' string to Dictionary - by deanhystad - May-13-2022, 03:44 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Need help converting string to int dedesssse 7 2,729 Jul-07-2021, 09:32 PM
Last Post: deanhystad
  Beautify dictionary without converting to string. sharoon 6 3,428 Apr-11-2021, 08:32 AM
Last Post: buran
  how to deal with problem of converting string to int usthbstar 1 1,992 Jan-05-2021, 01:33 PM
Last Post: perfringo
  Converting data in CSV and TXT to dictionary kam_uk 3 2,013 Dec-22-2020, 08:43 PM
Last Post: bowlofred
  Converting string to hex triplet menator01 4 4,359 Aug-03-2020, 01:00 PM
Last Post: deanhystad
  extract a dictionary from a string berc 4 2,884 Jul-30-2020, 06:58 AM
Last Post: berc
  simple f-string expressions to access a dictionary Skaperen 0 1,536 Jul-15-2020, 05:04 AM
Last Post: Skaperen
  converting string object inside a list into an intiger bwdu 4 2,649 Mar-31-2020, 10:36 AM
Last Post: buran
  problem coverting string data file to dictionary AKNL 22 6,500 Mar-10-2020, 01:27 PM
Last Post: AKNL
  Converting query string as a condition for filter data. shah_entrance 1 1,810 Jan-14-2020, 09:22 AM
Last Post: perfringo

Forum Jump:

User Panel Messages

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