Combining entries in a list

Trying to see about combining entries in two lists.
I used the site function to scrape a list of medication names as one list and another list for the dosages.

names = ["Aspirin", "Crestor", ...]
dosage = ["81mg po od", 10mg po od", ...]

I would like to see if I can combine these into a single list:

meds = ["Aspirin 81mg po od", "Crestor 10mg po od", ... ]

anyone have any ideas how to accomplish this?

Hi,

You can do something like that using the map() function.

For example:

{names=["Aspirin", "Crestor"]}
{dosage=["81mg po od", "10mg po od"]}

{meds=map(names, (name, index) -> name & " " & dosage[index])}

Meds: {=meds}

1 Like

Thanks!

Just out of curiosity is it possible make a keyed list from the above two lists in a similar way?

ex:

[
   ["name": "Aspirin", "dosage": "81mg po od"], 
   ["name": "Crestor", "dosage": "10mg po od"],
]

You sure can:

{names=["Aspirin", "Crestor"]}
{dosage=["81mg po od", "10mg po od"]}

{meds=map(names, (name, index) -> ["name": name, "dosage": dosage[index]])}

Meds: {=meds}

1 Like

Thanks again!