I am looping through lines of a csv in order to extract and transform data.
the csv looks like this:
alex, blue, 3
alex, blue, 4
liza, green, 2
alex, red, 4
alex, orange, 3
liza, blue, 2
liza, blue, 21
liza, yellow, 23
the result i want from the above are 2 files:
alex file
<blue>3, 4</blue>
<red>4</red>
<orange>3</orange>
liza file
<green>2</green>
<blue>2,21</blue>
<yellow>23</yellow>
i am not looking for you to solve this problem for me, but i am just looking for your guidance. i dont need help with the xml part, i would just like help on the LOGIC part.
thanks so much!
My preferred datastructure here (assuming order of names and colours isn’t important!) would be a nested
defaultdict. The usual usage is something like this:But we can also go one level deeper: