Concatenate subscriptions with ::
I am trying to build a string using ":" and then write that string to a file. The function gets two lists that include strings that represent amounts of money
[["$123,123,123", "$68,656", "$993,993,993,993", "$123,141,142,142"],
["$60", "$800,600", "$700,600,500", "$20,200,200,201"]]
It should be written as
"$123,123,123":"$68,656":"$993,993,993,993":"$123,141,142,142"
"$60":"$800,600":"$700,600,500":"$20,200,200,201"
I currently have something like this:
def save_amount (amount, moneys):
with open (moneys, "w") as file:
for i in amount:
moneys_s = str(i)
How to proceed?
+3
source to share
3 answers
l = [["$123,123,123", "$68,656", "$993,993,993,993", "$123,141,142,142"],
["$60", "$800,600", "$700,600,500", "$20,200,200,201"]]
[ ':'.join('"' + j + '"' for j in i) for i in l ]
Output:
['"$123,123,123":"$68,656":"$993,993,993,993":"$123,141,142,142"',
'"$60":"$800,600":"$700,600,500":"$20,200,200,201"']
+1
source to share