How to convert a nested list to a bulleted list

I have this list of lists:

List(1, List("A", "B", "C"))

How can I turn it into:

  • 1
    • A
    • B
    • C

Can the same formula be made to work for:

List(2, List(1, List("A", "B", "C")))

Hi @Connor_McCormick1

Is that what you wish ?

Cheers

Q

Yes this is the desired output, but I want both examples to be solved using the same formula.

that’s a little ‘rough’ request from a community champ’ … ! :yum:

At this point, did not figure out how to perform this without switchif (knowing that I’m cheating :wink: )

Will your data always have that kind of format ? if yes I assume this switchif isnt such a bad idea, but otherwise it’s difficult to me seeing how to cut the list, knowing how many levels of bullet point I would require.

Slicing/spliting the list and you loose the information about sublist. Using First/Last makes me loose middle data from example 1. Then, calling for better coda maker and wizard than me on this subject :wink:

1 Like

Is using a button an option, or does it have to be a live formula?

With a live formula this can be possible with some forced recalc magic to get it into a recursive loop.

I’d also say maybe make a pack formula for it?

2 Likes

Hey Paul. Yes I also tought of a button that could make it easier. Thanks for sharing the while loop in live formula, could totally interest me for another project. Cheers.

Yeah pack is probably the move. I just really wanted to do it in native formulas.

Thanks to all, you’re helping me feel less dumb for not being able to figure it out.

Ok if it can’t be in a simple formula, maybe it can be in a table formula.

Here’s the doc I’m working in:

You’ll see that there is a column called Subitems which nicely shows what an Item is made of:

I’d like to be able to @ reference that Basket and see its makeup in a bulleted list like this:

1 Like

The table’s rather easy, and I might have a wild idea with just random lists of text as well (provided all text pieces are unique). It’s too late here though; I’ll update this post when I’ll have solved it in my tomorrow.

Sorry, got busy for a few days.

Here’s the table solution: recursive collection of data from items:

With regular text it’s a bit tricky because Coda tried to “fix” the one vs list-of-one issue with another “magical” behavior where the list of one is silently treated as an item on its own:

The crazy approach I’d use here to determine what’s the level of the nesting of each given item is to… convert the list to text and calculate nesting by taking the number of [s and ]s and subtracting one from another :smiley: Of course this won’t work if the items themselves have [] characters (although it can be worked around with smarter regex) and if one item appears elsewhere, e.g. “Cheese” and “Cheese sticks” might trigger faulty results because of a substring being found twice

WithName(Input + "", InputToText,
  Input.ListCombine().ForEach(
    InputToText.Find(CurrentValue).WithName(FoundPosition,
    InputToText.Left(FoundPosition).WithName(AllPreText,
      List(
        AllPreText.RegexReplace("[^\[]", "").Length() - AllPreText.RegexReplace("[^\]]", "").Length(),
        CurrentValue
      )
    ))
  ).ForEach(
    CurrentValue.Last().BulletedList().IndentBy(CurrentValue.First() - 1)
  ).Concatenate()
)

Update: Fixed this by wrapping the list into an object first. This way Coda preserves the lists properly (turns it into proper JSON):

3 Likes

This is super useful Connor! (For some reason, the second video on the Items page is not working for me.)