jwaldner
MapSet.difference is reordring my list how to avoid that
I am just learning and am writing a word game.
I have a list of letters ordered by frequency of use and am doing a MapSet.difference() with letters [a-z] sorted by frequency of use & used letters to determine the next guess for an automated client
that works fine but the function re orders the new difference list alphabetically
I wanted to keep the [f] list order then just pick the next most frequent letter for a guess
f =
[“e”, “a”, “r”, “i”, “o”, “t”, “n”, “s”, “l”, “c”, “u”, “d”, “p”, “b”, “f”, “g”,
“h”, “j”, “k”, “m”, “q”, “v”, “w”, “x”, “y”, “z”]
s =
[“a”, “b”, “c”]
r = MapSet.difference(MapSet.new(f),MapSet.new(s))
the list does not start with “r” anymore [it’s new and that is fine, but I wanted to do an Enum.at(..0) to pick the next letter off the list… ]
r is {
MapSet.new([“d”, “e”, “f”, “g”, “h”, “i”, “j”, “k”, “l”, “m”, “n”, “o”, “p”,
“q”, “r”, “s”, “t”, “u”, “v”, “w”, “x”, “y”, “z”])
}
is there a way to do this?
Thanks!!
Most Liked
NobbZ
Sets are generally unordered.
So any order you observe is by accident and has to be considered an implementation detail.
If you need to maintain order, a MapSet is not the correct data structure to use.
zachallaun
Try using the -- operator on your lists directly instead.
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance









