python - Concatenating sublists with ":" -
i'm trying build string using ":" , write string file. function gets 2 lists include strings, 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 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"
currently have this:
def save_amount (amount, moneys): open (moneys, "w") file: in amount: moneys_s = str(i)
how proceed?
first flatten list , use join
, use list comprehension here :
>>> [ ':'.join('"' + j + '"' j in i) in l ] ['"$123,123,123":"$68,656":"$993,993,993,993":"$123,141,142,142"', '"$60":"$800,600":"$700,600,500":"$20,200,200,201"']
Comments
Post a Comment