
Thus here the employee id and an intermediate dictionary make a key-value pair for the resultant dictionary to be dumped.Explore more instances related to python concepts from Python Programming Examples Guide and get promoted from beginner to professional programmer level in Python Programming Language.Ī CSV file, which stands for Comma Separated Values file, is a simple text file that maintains a list of data. For each intermediate dictionary a unique id is created and that serves as the key. The idea is to convert each employee’s detail into an intermediate dictionary and append that to one main resultant dictionary. How to convert if multiple records are stored in the text file ? Let us consider the following text file which is an employee record containing 4 rows. Only the key is separated from its value. This ensures in a key-value pair, the spaces in the value are not removed and those words are not split. Here split(None, 1) is used to trim off all excess spaces between a key-value pair and ‘1’ denotes split only once in a line. Output: Note the below line of code: command, description = line.strip().split(None, 1) When the above code is executed, if a JSON file exists in the given name it is written to it, otherwise, a new file is created in the destination path and the contents are written to it.


DevOps Engineering - Planning to Production.Python Backend Development with Django(Live).Android App Development with Kotlin(Live).Full Stack Development with React & Node JS(Live).Java Programming - Beginner to Advanced.Data Structure & Algorithm-Self Paced(C++/JAVA).

Data Structures & Algorithms in JavaScript.Data Structure & Algorithm Classes (Live).
