Practice your list logic in Coda

based on a public puzzle

--

It all started on Twitter when Scott Weir posted a challenge. I noticed it only a few days after and liked the logic. Below his challenge and the solution.

His solution is clever and a bit complicated, mainly due to the syntax. The inline comments help. First have a look at the result above, it is all styled well.

code shared by Scott Weir

I would not have thought about using MaxBy() , I cannot even remember I used this function. It is nevertheless a good one, it filters the list and only takes the unique and highest values. More about this it here.

My contribution came in two parts. Scott showed me that my initial idea was not fully working, mainly because I did not filter out on dots and commas in the text and indeed every last word in a phrase had a dot glued to his tail. In his contribution you see how he tries to solve with Regex the issue, but his approach suffers from incompleteness. Using Regex presupposes you know a bit how to apply it or at least how to find the correct Regex syntax for this specific problem (you can google it or ask an AI). My idea was to circumvent the regex logic to show new makers that you can do a lot using only basic Coda Functions.

The goal is to get a count of unique words sorted in groups that contain words with an equal amount of letters, thus excluding dots etc. Are you new to Coda, then I invite you to read this blog first:

7 steps

We solve this puzzle in 7 main steps. The last step (number 7) is the formatting of the outcome. The exercise is about the steps we need to get there.

Step 01 — turn the text into a list of words

this is a simple step, but you have to see the logic that words are separated by spaces and thus we split the text on theses spaces to get all words

Step 02: filter out non letters and numbers

We only want to have words, not words with dots and commas glued to it. This issue I overlooked in my first effort. Here I solved it by using a simple list that contains all letters and numbers appearing in the English language. I first asked the AI in Coda, but the result was disappointing, so I asked Google Bard. This one gave me the formatted list. We can only use this list intelligently when we evaluate the words one by one. Would we have removed the reading symbols from the complete texts, it becomes impossible to recompose the words. We thus first take the words, we turn them into lower case, we split the words and we filter the outcome (letters per sub lists) against the list of letters and numbers we defined.

Step 03: unique words

We turn the filtered list into words by joining the letters per sub list and we make sure we only have unique words.

Step 04 unique letter counts

Since all words are clean, we count the letters in each word by using the function length(). We take the unique values. It is in this context the MaxBy() would replace the Unique() function, which makes sense and shortens the function. However it does not improve the readability. A large part of our work is the simplification of processes and we get there better (and without documentation) when the functions we develop are good to follow. For example, when I name a function, I avoid names that are equal to function names by adding ‘the’ as prefix and I often use the same concepts like ‘outCome’.

Step 05 — count the unique numbers

This part is maybe less obvious. Let me try to explain it. When you have list of words and you have an other list that tells the letters per word you see a range of numbers starting at one (for the word ‘a’), going to 2 (‘an’), to 3 (‘the’) and so on. The result is a list of numbers like 1,2,3,4,5,7,8,9. This example has no words with 6 letters. When we want to evaluate this list, we want to evaluate each value in this list and thus we need something to reference each position in this list. We thus need a virtual index and this would be 1,2,3,4,5,6,7,8. Since these lists look similar, it can be confusing.

Step 06 — get the words by character count

In this part it all comes together. We take the list of words, we filter each word on its length and we look per word if it contains 1 character or 2, or 3 or 4 or 5 etc. We can only do so if we check the complete list with options and for this we need the step 6. The outcome are groups of words that all have the same amount of characters.

Step 07- format the outcome

This is a relative easy step once you know how the format function works. I wrote about this function before, have a look here. In the by Scott Weir provided solution a few unsupported functions surfaced. In general I try to avoid them, although the outcome looks wonderful. The main thing here is to flatten the list by adding ToText() to the outcome to get per category (1 letter, 2 letters, 3 letters) the right string.

the formatted outcome

As you can see, there is no need for Regex once you create your own list of letters and symbols. I hope that this insight helps new makers to see that the evaluation of (sub) lists can be learned. It is matter of practice and you only need a few functions to get the job done, none of them exotic.

Our job when working with clients is not only to provide good to follow solutions, but also good to follow code they can reuse and apply elsewhere, maybe with some variation. There are situations you have no other choice then to apply Regex or JSON, but often it can be avoided ⤵️.

My name is Christiaan and blog about Coda. Since the summer of 2023 mainly about how to Coda with AI to support organisations dealing with texts and templates. My blogs are for beginners and experienced users. The central theme is that in Coda everything is a list.

I hope you enjoyed this article. If you have questions feel free to reach out. Though this article is for free, my work (including advice) won’t be, but there is always room for a chat to see what can be done. You find my (for free) contributions to the Coda Community and on Twitter.

Coda comes with a set of building blocks ー like pages for infinite depth, tables that talk to each other, and buttons that take action inside or outside your doc ーso anyone can make a doc as powerful as an app (source).

Not to forget: the Coda Community provides great insights for free once you add a sample doc.

--

--

Christiaan Huizer

I write about how to Coda . You find blogs for beginners and experienced makers. I publish about 1 / week. Welcome!