I have:
ListOne = ['foo', 'bar', ..]
I now want to create a new List by zipping ListOne with ListTwo. ListTwo looks like this:
ListTwo = [{count, 1},{count, 1},{count,1}, ..]
What’s a nice way to dynamically generate ListTwo? Every list item will be the same.
I want to feed the result of the zip to dict:from_list. So maybe a zip is not the best approach.
While your question could be more specific, my guess is that you want to use a dictionary to store key, value pairs where the value is a counter. What you are trying to achieve by asking this, is how to initialize the dict with the counter set to 1.
The folloing code will create a new dict, where the key is the key from ListOne and the value is 1:
Now, to increment these counters, you can use
dict:update_counter/3:To decrement, you would simply give a negative number as the increment.
It is also worth noting that
dict:update_counter/3, will create the key in the dict if it is not already present, with the given increment as the initial value.