

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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 split a semicolon-separated string to a dictionary in Python?
If you have strings like:
"Name1=Value1;Name2=Value2;Name3=Value3"
and you want to convert it to a dictionary, it is fairly easy. You could simply split on ';' and then on '=' and pass this to dict constructor.
For example
>>> s = "Name1=Value1;Name2=Value2;Name3=Value3" >>> dict(item.split("=") for item in s.split(";")) {'Name2': 'Value2', 'Name3': 'Value3', 'Name1': 'Value1'}
- Related Questions & Answers
- How to split comma and semicolon separated string into a two-dimensional array in JavaScript ?
- How to split a string in Python
- How to convert a String representation of a Dictionary to a dictionary in Python?
- How to convert a string to dictionary in Python?
- How to convert the string representation of a dictionary to a dictionary in python?
- How to translate a python string according a given dictionary?
- How to split a string in Java?
- How to split a string in Golang?
- How to split string by a delimiter str in Python?
- Convert string dictionary to dictionary in Python
- Python program to split and join a string?
- Python program to create a dictionary from a string
- How to split a string with a string delimiter in C#?
- How do I serialize a Python dictionary into a string, and then back to a dictionary?
- How to define a Python dictionary within dictionary?
Advertisements