List syntax?

I’m building an app and have setup some config fields for the user to enter text into. Basically I just want to loop through the config fields (which are empty by default) and for every one that’s filled in (ie NOT empty), add them to a list variable (arrays in Javascript, for example).

So for instance, if the user were to fill in the following configs like this:

cfg1 = ""
cfg2 = "Name"
cfg3 = ""
cfg4 = ""
cfg5 = "Location"

… I want to end up with this:
things = ["Name", "Location"]

What’s the proper syntax for looping through all the config fields and checking if they are empty or not, and if not, adding them to a new list?

Also, is there a better reference doc than this? It does talk about some details but it doesn’t really offer many examples. For instance, I looked up lists and it doesn’t show how to create a list, or how to add items. It mentions the function used but that’s it, no examples. Looking for something a little more detailed, if anything like that exists. I come from a Javascript background so I can translate concepts usually but it’s tough when you aren’t sure what the equivalent syntax is.

Thoughts?

Here is how to manipulate lists in starlark: https://bazel.build/rules/lib/core/list

Starlark is a subset of Python and share very similar syntax. Take a look at the Python documentation to get a feel for how lists work 5. Data Structures — Python 3.12.5 documentation

# Assume you have some config fields
cfg1 = ""
cfg2 = "Name"
cfg3 = ""
cfg4 = ""
cfg5 = "Location"

# List of config values
configs = [cfg1, cfg2, cfg3, cfg4, cfg5]

# List comprehension to filter out empty values
things = [cfg for cfg in configs if cfg != ""]

print(things)  # Output: ["Name", "Location"]