-2

Most of the solutions I've come across involve joining items within a list, but my question is about joining an item from a list of strings with another string outside of the list.

In the script below, the desired output is "USD.JPY.SPOT.SPR" as a string, and then the subsequent pairings.

I've tried pairing.join(".SPOT.SPR") and pairing+".SPOT.SPR" but they've not generated the desired output.

pairings = ["USD.JPY", "USD.HKD", "AUD.USD", "EUR.USD", "GBP.USD", "USD.SGD"]
for pairing in pairings:
    print(pairing.join(".SPOT.SPR"))
ktan
  • 129
  • 1
  • 9
  • 1
    What *is* the desired output and why did `pairing+".SPOT.SPR"` did not give it? You've only shown `"USD.JPY.SPOT.SPR"` which is a single string. What is your desired output from the list? – Tomerikoo Jun 02 '20 at 11:23

2 Answers2

0

Try iterating through the list index and '+' to concatenate -

pairings = ["USD.JPY", "USD.HKD", "AUD.USD", "EUR.USD", "GBP.USD", "USD.SGD"]
for i in range(len(pairings)):
    print(pairings[i]+(".SPOT.SPR"))
0

Just replace your join with string concatenation

pairings = ["USD.JPY", "USD.HKD", "AUD.USD", "EUR.USD", "GBP.USD", "USD.SGD"]
for pairing in pairings:
    print(pairing+".SPOT.SPR")
Sarvesh
  • 99
  • 5