====== Reading .dsv files into a dictionary ====== To work with the data from file ''truth.dsv'', it will be convenient to read them into a dictionary which would tell you for each file what numeral or character is depicted on the image. ===== Reading the .dsv file manually ===== Reading the data into a dictionary is not hard, you can try to implement it yourself: * open the file for reading * for each line in the file: * remove the white space in the beginning and at the end of the line using [[https://docs.python.org/3/library/stdtypes.html?highlight=strip#str.strip|str.strip()]] * call [[https://docs.python.org/3/library/stdtypes.html?highlight=split#str.split|str.split(':')]] method that will split the line into two parts using the colon as a separator * create key-value pair in the dictionary using the first part of the line as key and the second part as value ===== Take advantage of ''csv'' module ===== Python contains standard module [[https://docs.python.org/3/library/csv.html|csv]] for easier work with ''.csv'', ''.dsv'' or similar file formats. You can use it to read the ''truth.dsv'' file in a similar way as described [[https://www.delftstack.com/howto/python/python-csv-to-dictionary/#use-the-csv-module-to-convert-csv-file-to-dictionary-in-python|here]]. You will only have to correctly specify the separator, i.e., set the parameter ''delimiter=":"'' when calling ''csv.reader()''. Nevertheless, in this particular case the use of ''csv'' module will not save you much work (in comparison to manual processing of the ''.csv'' file as suggested above).