Remapping a list/Repeats

I have a snippet that uses a repeat to work it's way through a sequence of a list. Let's just say this list, for example:

[Apple, Apple, Banana, Orange]

As part of that repeat, I'm needing to quantify the unique value to the list. Meaning, that while Apple occupies both the first & second numerical value of the 4 value list, I need to be able to pull the #2 when I sequence through to "banana" and then #3 when I get to orange. I'm not 100% sure how to go about this, but a thought I've had is to generate a list that remaps the values of the list into a numerical one that also indicates the match. So it would be [1, 1, 2, 3] That way when I cycle through the 3rd instance of the list, the value of that is "2".

Any idea how to do that?

hey kevin -- what do you mean by "pull" a value as you sequence through it? Do you want to remove duplicates before you do the repeat? Do you want to be able to pull out specific data from the repeat but only for 1 instance of a duplicated item (e.g. if Apple appears twice, you need info about the second apple but not the first)? Or is it something else entirely and I'm missing it?

OK let me adjust to realworld data so you can see what I'm doing. And then you can tell me I'm doing it in a stupidly complicated way :slight_smile:

Outbound City: ["Washington/Dulles", "Lome", "Addis Ababa"]
Arrival City: ["Lome", "Addis Ababa", "Johannesburg"]
Departure Time: ["9:55 pm", "12:55 pm", "11:30 pm"]
Arrival Time: ["11:55 am", "9:20 pm", "3:55 am"]
Airline: ["Ethiopian Airlines", "Ethiopian Airlines", "Ethiopian Airlines"]
Flight Number: ["517", "517", "859"]
Airline Number: ["Ethiopian Airlines 517", "Ethiopian Airlines 517", "Ethiopian Airlines 859"]
Booking Cabin: ["V", "V", "Y"]

Ethiopian 517 is actually a single flight that stops in Lome on the way to Addis Ababa. I'm cycling through a repeat for each item on the Airline Number and then doing a check to see if the data matches the previous item. If so, then I need to do some things, and if not, then I do other things.

{repeat: for segstosell in (seq(2, count(airlinenumber)))}{if: airlinenumber[segstosell] <> airlinenumber[segstosell-1]}{=bookingcabin[segstosell]}{endif}

I can't just reduce that list, b/c it won't know which things in the other lists to ignore (though there's probably a way to reduce the duplicate position on each list type?) So as this sequents runs through it has 3 sequences to run though, but in this example it is outputting no data on the 2nd one b/c the airline number matches the first one. Then when it outputs the 3rd sequence of data I need it to be able to say this is the 2nd unique airline number.

Of note, the duplicate airline number could exist in any sequence of the list, so it isn't always 1&2.

Does that help or just make it murkier?

Is there a reason that you couldn't filter the list prior to the repeat? You don't have to remove the duplicates from the original variable if having those there are useful, but you can filter before the repeat happens. Something like this:

{`airline number`=["Ethiopian Airlines 517", "Ethiopian Airlines 517", "Ethiopian Airlines 859"]}
Here's your flight numbers:
{repeat: for segtosell in unique(`airline number`)}{=segtosell}
{endrepeat}

I need booking Cabin to correspond with what has been filtered so I can't just reduce b/c I need to know which of the 3 booking cabin fields to use and which to ignore.

ah duh that makes sense, and I see that you're also doing the repeat on a sequence, not on the list of airlines, so you need to use that to determine positions anyway. hmmmmm

I'm still thinking about this, let me try a few things to see if i can come up with anything useful and will post back here shortly. If not... let's do a call to talk it through.

While I'm testing things: is there any possibility to bring your info in as a keyed list instead of as separate lists? That might make things easier, but I'm still kicking around ideas.

{keyed=[["Outbound City": "Washington/Dulles", "Arrival City": "Lome", "Departure Time": "9:55 pm", "Arrival Time": "11:55am", "Airline": "Ethiopian Airlines", "Flight Number": "517", "Airline Number": "Ethiopian Airlines 517", "Booking Cabin": "V"], ["Outbound City": "Lome", "Arrival City": "Addis Ababa", "Departure Time": "12:55 pm", "Arrival Time": "9:20pm", "Airline": "Ethiopian Airlines", "Flight Number": "517", "Airline Number": "Ethiopian Airlines 517", "Booking Cabin": "V"], ["Outbound City": "Addis Ababa", "Arrival City": "Johannesburg", "Departure Time": "11:30 pm", "Arrival Time": "3:55am", "Airline": "Ethiopian Airlines", "Flight Number": "859", "Airline Number": "Ethiopian Airlines 859", "Booking Cabin": "Y"]]}

It's all regex'd stuff from clipboard data. I suppose there might be a way to make it a keyed list, but I'm not sure of how.

Call is fine :slight_smile:

@Kevin_Roberts
Does this work?

{list=["Apple", "Apple", "Banana", "Orange"]} {unique_list=unique(list)} {unique_index=map(unique_list, (v) -> location(list, v))} {=unique_index}

Then you can do something like:

{`Outbound City`=["Washington/Dulles", "Lome", "Addis Ababa"]}
{`Arrival City`= ["Lome", "Addis Ababa", "Johannesburg"]}
{`Departure Time`= ["9:55 pm", "12:55 pm", "11:30 pm"]}
{`Arrival Time`= ["11:55 am", "9:20 pm", "3:55 am"]}
{Airline= ["Ethiopian Airlines", "Ethiopian Airlines", "Ethiopian Airlines"]}
{`Flight Number`= ["517", "517", "859"]}
{`Airline Number`= ["Ethiopian Airlines 517", "Ethiopian Airlines 517", "Ethiopian Airlines 859"]}
{`Booking Cabin`= ["V", "V", "Y"]}

{unique_list=unique(`Airline Number`)} {unique_index=map(unique_list, (v) -> location(`Airline Number`, v))}

{repeat: for id in unique_index}
{=`Airline Number`[id]} | {=`Outbound City`[id]} | {=`Departure Time`[id]}
{endrepeat}

3 Likes

Took a little finagling but Andrew and I got it working. Many thanks! I really appreciate your help with this!

2 Likes