vmg
I’m having trouble trying to zip lists of different lengths because elixir only returns the first match of each list.
I have the following list of lists:
[
["e5", "e7", "e7", "e8", "e8", "e2", "e2", "e0", "e0", "e0"],
["B5", "B5", "B5", "B3", "B1", "B1", "B1", "B0", "B1", "B1"],
["G5", "G5", "G5", "G2", "G2", "G2"],
["D7"]
]
Elixir return this:
[{“e5”, “B5”, “G5”, “D7”}]
And I would like to get the following list:
[
["D7", "G5", "B5", "e5"],
["G5", "B5", "e7"],
...,
["B1", "e0"]
]
Is there any way to accomplish this with zip or any other function?
Trending in Questions
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
Hello,
I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
Hi everyone,
I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding.
I sta...
New
Documentation
While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
So my question is quite simple and i have found no conclusive answer on forum, google or AI.
Should we use :erlang.float for Integer to ...
New
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
I’m new to elixir and just tried to install the elixirLS extension for VScode(ium) and it is throwing some errors that I would like help ...
New
Other Trending Topics
Edit: 2026 May 15 - This post is archived.
Mob is alive!!
Main docs: mob v0.7.11 — Documentation
A bit of explanation for the slightly c...
New
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Hi everyone!
The first release candidate for the Expert language server project is now available!
We’ve published a press release detai...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #ai
- #elixirconf-us
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #elixirconf-eu
- #metaprogramming
- #hex











Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
Sebb
not directly possible.
Sth like python’s zip_longest would be nice in
Enum.But even that would leave you with some handy work.
Hint: you could pad the lists with
nilto fill all up to length of the longest list, and then remove thenils after that.dimitarvp
If you don’t want to write your own recursive function helpers for this then your best bet is indeed filling up the smaller lists with a marker value –
nilor something else – and then just throw those away after the zipping operation, as @Sebb suggested.Sebb
yes, that seems to be the better way here.
akash-akya
@dimitarvp already suggested recursion, this is one way to do that using
unfoldSebb
or using
Enum.zipwith helpEiji
Here you go:
Helpful resources:
adamu
What should happen when the input is the following?
Sebb
what do you think is special about this input?
(isnt
dbgthe coolest thing?)adamu
Maybe it should be e2, nil, B1? Or something else.
But my real hypothesis was that the OP is not coming back. So far satisfied…
Eiji
I don’t think so:
nilshould stay only if it’s a part ofinput. In theory any solution which is addingnilvalues in the middle of process and later removes allnilvalues could be wrong. “Could” because author have specifiedStringvalues as the only possibility. Otherwise there should be at least oneatomorintegerin code examples.Since in
Elixirit’s common to usenilvalues similarly toundefined(in other languages) the mistake “is” at author side even if there are other solutions without such problem. I’m quoting “is” because it’s his/her first post and question is relatively simple which in my opinion should lead community to provide more “safe” answers anyway.The other argument against such solution could be question itself (without code). While examples shows
list(list(String.t()))as the only possibility, the question is more generic. Please pay attention that in question there is no word on what’s the contents of said lists which means we have herelist(list(term))instead, especially thatinputhere is extremely simple (it looks likeStringvalues are different only to easily catch incorrect zip cases).Also I would suggest to provide “safe” solutions “by default” as many people especially including junior developers are not used to look for all possible edge cases.