So this should be super easy but I'm struggling for a while now: I learn python at moment and there is this Task: I have string with data, sales data. Name of customer, price of goods etc...
daily_sales = """Leticia Manning;,;$15.70 ;,; green&purple;,;
09/15/17 , Mario Wallace ;,; $12.36 ;,;green ;,;
09/15/17,Lewis Glover;,; $13.66 ;,;
green&white;,;09/15/17, Gail Phelps ;,;$30.52
;,; green&white&blue ;,; 09/15/17 , Myrtle Morris
;,; $22.66 ;,; green&white&blue;,;09/15/17"""
I want to sort it in to list so it's readable.
def sort(daily_sales):
sales = daily_sales.replace(";,;", "|")
sales_list = sales.split(",")
transactions = []
for objects in sales_list:
transactions.append(objects.replace(" ", ""))
return transactions
print(sort(daily_sales))
So far so easy. This is my output:
['LeticiaManning|$15.70|green&purple|\n09/15/17',
'MarioWallace|$12.36|green|\n09/15/17',
'LewisGlover|$13.66|\ngreen&white|09/15/17',
'GailPhelps|$30.52\n|green&white&blue|09/15/17',
'MyrtleMorris\n|$22.66|green&white&blue|09/15/17']
But i want in front of and after the parting line one empty space. Like:
'LeticiaManning | $15.70 | green&purple | \n09/15/17'
But i have no idea how to implement it. I tried with .join but obviously it doesn't work. I thought about an interleaved for-loop but i have no idea how this could work.
'|'to' | 'print(sorted(...)))