I start out with this little ditty, but would need to clean it up, create key-value pairs and for each customer, create their own dictionary part of a list of customer dictonaries.
service_notes = ['Customer AliceJenkinsn',
'Car Hondan',
'Service Fifty_Thousandn','Customer BobElliotn',
'Car Toyota, Rav4, Silver, 2018n',
'Service Thirty_Thousand,n',
'Customer CharlieWallacen',
'Car Fordn',
'Service Ten_Thousandn']
Firstly, I cleaned up the listed string with overthinking by creating a delimited between would-be key-value pairs, but ran into difficulty in the Car Toyota section) and finally removed the line change.
then when I tried to split the values into key-value pairs, i got an error for using str split functions on a list. so made the list into a str… and well yeah. didnt work.
data_arr = [entry.replace(" ", ": ").replace(",:", " ").replace("n","") for entry in service_notes]
data_arr = str(data_arr)
sep = ': '
lst = data_arr.split(sep)
d = dict(zip(lst[0::2], lst[1::2]))
print(d)
end results is not a useable dictionary. nor could i create dictionaries for each customer entry.
{"['Customer": "AliceJenkins', 'Car", "Honda', 'Service": "Fifty_Thousand', 'Customer", "BobElliot', 'Car": "Totota Rav4 Silver 2018', 'Service", "Thirty_Thousand,', 'Customer": "CharlieWallace', 'Car", "Ford', 'Service": "Ten_Thousand']"}
Alari Koel is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1