# \#list

**URL:** https://forum.elixirforum.com/tag/list/1210.md

[Latest](https://forum.elixirforum.com/latest.md) · [Categories](https://forum.elixirforum.com/categories.md) · [Tags](https://forum.elixirforum.com/tags.md)

---

## [What's the approach for handling lists that allows for optimized traversal?](https://forum.elixirforum.com/t/whats-the-approach-for-handling-lists-that-allows-for-optimized-traversal/76584)

<div class="topic-metadata">

**Author:** [@nseaSeb](https://forum.elixirforum.com/u/nseaSeb)\
**Replies:** 15\
**Last updated:** [September 7, 2026, 10:04pm UTC](https://forum.elixirforum.com/t/whats-the-approach-for-handling-lists-that-allows-for-optimized-traversal/76584 "2026-09-07T22:04:33Z")

</div>

Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (something like “vector lib” or similar?). I’m having trouble finding the information sin…

---

## [How does List vs Tuple preformance work](https://forum.elixirforum.com/t/how-does-list-vs-tuple-preformance-work/74397)

<div class="topic-metadata">

**Author:** [@Trolleger](https://forum.elixirforum.com/u/Trolleger)\
**Replies:** 2\
**Last updated:** [February 24, 2026, 9:02pm UTC](https://forum.elixirforum.com/t/how-does-list-vs-tuple-preformance-work/74397 "2026-02-24T21:02:08Z")

</div>

I heard that editing a tuple is a much more expensive operation then editing a list i just don’t get the why, when a list is mutated a new list made in memory when edited, same as tuple; they use references from other v…

---

## [Add \`List.first!/1\` and \`List.last!/1\`](https://forum.elixirforum.com/t/add-list-first-1-and-list-last-1/74116)

<div class="topic-metadata">

**Author:** [@pierrelegall](https://forum.elixirforum.com/u/pierrelegall)\
**Replies:** 18\
**Last updated:** [January 29, 2026, 11:48pm UTC](https://forum.elixirforum.com/t/add-list-first-1-and-list-last-1/74116 "2026-01-29T23:48:29Z")

</div>

Problem Currently, List.first/2 and List.last/2 return a default value (or nil) when the list is empty. However, there are cases where an empty list represents a bug in the program, and silently returning nil can lead to…

---

## [Traverse nested list and if the list has two elements apply function](https://forum.elixirforum.com/t/traverse-nested-list-and-if-the-list-has-two-elements-apply-function/70135)

<div class="topic-metadata">

**Author:** [@afhuertass](https://forum.elixirforum.com/u/afhuertass)\
**Replies:** 5\
**Last updated:** [March 26, 2025, 12:23am UTC](https://forum.elixirforum.com/t/traverse-nested-list-and-if-the-list-has-two-elements-apply-function/70135 "2025-03-26T00:23:03Z")

</div>

Hi! I have been dealing with some problem where I have a nested list, I want to keep the nested structure, but if the list is a two elements list, then i want to apply a custom function (I’m dealing with multypolygon co…

---

## [Override Access.get to support using brackets to access an index of a list](https://forum.elixirforum.com/t/override-access-get-to-support-using-brackets-to-access-an-index-of-a-list/69087)

<div class="topic-metadata">

**Author:** [@user20230119](https://forum.elixirforum.com/u/user20230119)\
**Replies:** 2\
**Last updated:** [January 30, 2025, 4:38am UTC](https://forum.elixirforum.com/t/override-access-get-to-support-using-brackets-to-access-an-index-of-a-list/69087 "2025-01-30T04:38:10Z")

</div>

I want to use get\_in(data, keys) for a nested map with some values having a list with maps. map = %{a: 1, aa: \[%{b: 2}, %{bb: 22}\], aaa: 111} get\_in(map, \[:aa, 1, :bb\]) # =\> 22 Is there a way to override Access.get to …

---

## [List append (++) does not return a list](https://forum.elixirforum.com/t/list-append-does-not-return-a-list/66569)

<div class="topic-metadata">

**Author:** [@polovy](https://forum.elixirforum.com/u/polovy)\
**Replies:** 19\
**Last updated:** [October 10, 2024, 12:29pm UTC](https://forum.elixirforum.com/t/list-append-does-not-return-a-list/66569 "2024-10-10T12:29:35Z")

</div>

I am going through some tutorials, and one of the tasks is to create a list of items by taking first two elements of the existing item and appending them to the end of said list. The problem I have is that for some numer…

---

## [Strange Output When Filtering List with \`Enum.filter/2\`](https://forum.elixirforum.com/t/strange-output-when-filtering-list-with-enum-filter-2/64190)

<div class="topic-metadata">

**Author:** [@holasoymas](https://forum.elixirforum.com/u/holasoymas)\
**Replies:** 2\
**Last updated:** [June 13, 2024, 12:24pm UTC](https://forum.elixirforum.com/t/strange-output-when-filtering-list-with-enum-filter-2/64190 "2024-06-13T12:24:01Z")

</div>

I’m encountering a strange issue when using Enum.filter/2 in my Elixir script. The problem occurs when I filter a list with a condition that elements should be greater than a certain value using pipe operator. pipe\_ope…

---

## [How to make an infinate nested list](https://forum.elixirforum.com/t/how-to-make-an-infinate-nested-list/47682)

<div class="topic-metadata">

**Author:** [@dongdigua](https://forum.elixirforum.com/u/dongdigua)\
**Replies:** 8\
**Last updated:** [April 28, 2024, 4:47pm UTC](https://forum.elixirforum.com/t/how-to-make-an-infinate-nested-list/47682 "2024-04-28T16:47:20Z")

</div>

in python, there is \>\>\> a=\[\] \>\>\> a.append(a) \>\>\> a \[\[...\]\] how to implement this in elixir?

---

## [Elixir converting \[55\] into '7'](https://forum.elixirforum.com/t/elixir-converting-55-into-7/62236)

<div class="topic-metadata">

**Author:** [@henry-iteron](https://forum.elixirforum.com/u/henry-iteron)\
**Replies:** 4\
**Last updated:** [March 11, 2024, 5:30pm UTC](https://forum.elixirforum.com/t/elixir-converting-55-into-7/62236 "2024-03-11T17:30:32Z")

</div>

In Elixir, I have to use the list of integers and work with that, If my input is \[55\] it gives the data as ‘7’ but I need it to be \[55\] only. How can I maintain it? If I try this as \[‘55’\], it’s working fine. But I wan…

---

## [Allowing an ignored member in list construction?](https://forum.elixirforum.com/t/allowing-an-ignored-member-in-list-construction/61643)

<div class="topic-metadata">

**Author:** [@Oliver](https://forum.elixirforum.com/u/Oliver)\
**Replies:** 22\
**Last updated:** [February 14, 2024, 4:11pm UTC](https://forum.elixirforum.com/t/allowing-an-ignored-member-in-list-construction/61643 "2024-02-14T16:11:12Z")

</div>

One common problem we face in constructing lists is that there is (AFAIK) no support for conditionally inserting members into list declarations. You can’t write: allow\_even? = false \[ 1, if allow\_even? do 2 end, 3 \] b…

---

## [Nested list of maps add or update another nested key](https://forum.elixirforum.com/t/nested-list-of-maps-add-or-update-another-nested-key/60886)

<div class="topic-metadata">

**Author:** [@shahryarjb](https://forum.elixirforum.com/u/shahryarjb)\
**Replies:** 2\
**Last updated:** [January 10, 2024, 9:51pm UTC](https://forum.elixirforum.com/t/nested-list-of-maps-add-or-update-another-nested-key/60886 "2024-01-10T21:51:00Z")

</div>

I have a nested list that should follow a rules to update a record or add a record. I have a keys list which is the path I need to update or add Entry list \[ %{ name: :actor, opts: \[ str…

---

## [List limit number of items](https://forum.elixirforum.com/t/list-limit-number-of-items/57088)

<div class="topic-metadata">

**Author:** [@mushu8](https://forum.elixirforum.com/u/mushu8)\
**Replies:** 6\
**Last updated:** [July 19, 2023, 1:57pm UTC](https://forum.elixirforum.com/t/list-limit-number-of-items/57088 "2023-07-19T13:57:40Z")

</div>

Hi, is there a preferred way to keep a list number of items under a certain limit ? In my project there is a GenServer module receiving events and stacking them in a list where only the X last one must be kept for anal…

---

## [Need advise to update nested list 3-level](https://forum.elixirforum.com/t/need-advise-to-update-nested-list-3-level/55057)

<div class="topic-metadata">

**Author:** [@shahryarjb](https://forum.elixirforum.com/u/shahryarjb)\
**Replies:** 18\
**Last updated:** [April 9, 2023, 6:05am UTC](https://forum.elixirforum.com/t/need-advise-to-update-nested-list-3-level/55057 "2023-04-09T06:05:57Z")

</div>

Hello friends, I have a list that I want to update it (3 level nested), and I need your suggestion to create better code The list elements = \[ %{ children: \[ %{ children: \[ %{ c…

---

## [List as functions argument never matched](https://forum.elixirforum.com/t/list-as-functions-argument-never-matched/54270)

<div class="topic-metadata">

**Author:** [@rrrr](https://forum.elixirforum.com/u/rrrr)\
**Replies:** 2\
**Last updated:** [March 2, 2023, 3:15pm UTC](https://forum.elixirforum.com/t/list-as-functions-argument-never-matched/54270 "2023-03-02T15:15:59Z")

</div>

I got 2 warnings and “unexpected” behavior when trying to match argument as a list. Is this code incorrect? How can I match a argument as a List? (It’s first code i am writing by myself :innocent: I was trying to be clo…

---

## [List Comparison (how it works)](https://forum.elixirforum.com/t/list-comparison-how-it-works/33985)

<div class="topic-metadata">

**Author:** [@vermaxik](https://forum.elixirforum.com/u/vermaxik)\
**Replies:** 5\
**Last updated:** [January 11, 2023, 8:37am UTC](https://forum.elixirforum.com/t/list-comparison-how-it-works/33985 "2023-01-11T08:37:26Z")

</div>

Hello Elixirforum, Could you please explain how List Comparison works in Elixir? Why such list of integers returns true iex(15)\> \[3,10\] \> \[3,3,3,3\] true And the same example list of strings: iex(16)\> \["3","10"\] \> \["…

---

## [Read data from a text file and generate a map](https://forum.elixirforum.com/t/read-data-from-a-text-file-and-generate-a-map/52226)

<div class="topic-metadata">

**Author:** [@kimc0de](https://forum.elixirforum.com/u/kimc0de)\
**Replies:** 4\
**Last updated:** [December 3, 2022, 4:54pm UTC](https://forum.elixirforum.com/t/read-data-from-a-text-file-and-generate-a-map/52226 "2022-12-03T16:54:53Z")

</div>

Hi all, I have a .txt file with information like this 11111 0 11112 1 11113 2 11114 3 11115 4 11116 5 11121 6 11122 7 … 66664 zzgl 66665 zzz 66666 zzzz What I have to do: read the file return a map like th…

---

## [How to compare integer in a list and return a list of integer and its frequencies](https://forum.elixirforum.com/t/how-to-compare-integer-in-a-list-and-return-a-list-of-integer-and-its-frequencies/51623)

<div class="topic-metadata">

**Author:** [@kimc0de](https://forum.elixirforum.com/u/kimc0de)\
**Replies:** 8\
**Last updated:** [November 8, 2022, 7:17am UTC](https://forum.elixirforum.com/t/how-to-compare-integer-in-a-list-and-return-a-list-of-integer-and-its-frequencies/51623 "2022-11-08T07:17:17Z")

</div>

Hi all, I’m trying to do some Leetcode exercises in elixir. I have a function that takes an integer and it needs to return a list of lists that includes the digit frequency and the digit itself. Something list this for…

---

## [Itertating a 2D matrix](https://forum.elixirforum.com/t/itertating-a-2d-matrix/50849)

<div class="topic-metadata">

**Author:** [@Anshul-13J](https://forum.elixirforum.com/u/Anshul-13J)\
**Replies:** 12\
**Last updated:** [October 9, 2022, 9:31pm UTC](https://forum.elixirforum.com/t/itertating-a-2d-matrix/50849 "2022-10-09T21:31:10Z")

</div>

Hey everyone, I am new to Elixir language and I am having some issues while writing a piece of code. What I am given is a 2D array like list1 = \[ \[1 ,2,3,4,"nil"\], \[6,7,8,9,10,\], \[11,"n…

---

## [ExUnit: preferred way to test a list element?](https://forum.elixirforum.com/t/exunit-preferred-way-to-test-a-list-element/50781)

<div class="topic-metadata">

**Author:** [@dogweather](https://forum.elixirforum.com/u/dogweather)\
**Replies:** 3\
**Last updated:** [October 6, 2022, 4:28am UTC](https://forum.elixirforum.com/t/exunit-preferred-way-to-test-a-list-element/50781 "2022-10-06T04:28:27Z")

</div>

I’m TDD’ing parsing code, and I’d been writing tests like this: test "First - 001", %{sections\_001: sections} do assert List.first(sections).number == "1.001" end But then I realized I could also write t…

---

## [Zip list of different lengths](https://forum.elixirforum.com/t/zip-list-of-different-lengths/50233)

<div class="topic-metadata">

**Author:** [@vmg](https://forum.elixirforum.com/u/vmg)\
**Replies:** 13\
**Last updated:** [September 20, 2022, 3:14pm UTC](https://forum.elixirforum.com/t/zip-list-of-different-lengths/50233 "2022-09-20T15:14:18Z")

</div>

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"\]…

---

## [What's proper elixir way to update an \*\*ordered\*\* list by key](https://forum.elixirforum.com/t/whats-proper-elixir-way-to-update-an-ordered-list-by-key/50187)

<div class="topic-metadata">

**Author:** [@artem](https://forum.elixirforum.com/u/artem)\
**Replies:** 3\
**Last updated:** [September 13, 2022, 3:54pm UTC](https://forum.elixirforum.com/t/whats-proper-elixir-way-to-update-an-ordered-list-by-key/50187 "2022-09-13T15:54:50Z")

</div>

Hi all I am playing with a weather forecast LiveView (just a hobby project to learn elixir on something that looks realistic). The list of days I want to display is certainly ordered. Fetching weather takes a HTTP call…

---

## [Building map from list of columns and list of values](https://forum.elixirforum.com/t/building-map-from-list-of-columns-and-list-of-values/50025)

<div class="topic-metadata">

**Author:** [@hauks96](https://forum.elixirforum.com/u/hauks96)\
**Replies:** 11\
**Last updated:** [September 9, 2022, 9:32pm UTC](https://forum.elixirforum.com/t/building-map-from-list-of-columns-and-list-of-values/50025 "2022-09-09T21:32:46Z")

</div>

I’m trying to implement an efficient generic function to map the results from a Postgrex call into a map. Any suggestions? Example result from postgrex: %Postgrex.Result{ columns: \["first\_column", "second\_column"\],…

---

## [How to check if a list is a sublist(out of order list) of another list](https://forum.elixirforum.com/t/how-to-check-if-a-list-is-a-sublist-out-of-order-list-of-another-list/32888)

<div class="topic-metadata">

**Author:** [@Ajaxdone](https://forum.elixirforum.com/u/Ajaxdone)\
**Replies:** 17\
**Last updated:** [July 22, 2022, 10:45pm UTC](https://forum.elixirforum.com/t/how-to-check-if-a-list-is-a-sublist-out-of-order-list-of-another-list/32888 "2022-07-22T22:45:34Z")

</div>

l1 = \["1","2","5","9"\] l2 = \["1","9"\] List.contains?(l1,l2) Anything like this? to check if l2 is a sublist of l1. I know can use Enum.each and check one by one, just want to know if anything like that. thanks

---

## [Efficient deduplicating consecutive elements in a list](https://forum.elixirforum.com/t/efficient-deduplicating-consecutive-elements-in-a-list/47405)

<div class="topic-metadata">

**Author:** [@silverdr](https://forum.elixirforum.com/u/silverdr)\
**Replies:** 4\
**Last updated:** [April 29, 2022, 11:51am UTC](https://forum.elixirforum.com/t/efficient-deduplicating-consecutive-elements-in-a-list/47405 "2022-04-29T11:51:44Z")

</div>

I receive a list, which may contain (multiple times) two or more identical elements consecutively. Something like \["a", "b", "c", "b", "b", "c", "b", "d", "d"\] After processing there should be no identical elements one…

---

## [Fill a list after Enum.Each Loo^p](https://forum.elixirforum.com/t/fill-a-list-after-enum-each-loo-p/47277)

<div class="topic-metadata">

**Author:** [@xgeek116](https://forum.elixirforum.com/u/xgeek116)\
**Replies:** 5\
**Last updated:** [April 18, 2022, 8:59pm UTC](https://forum.elixirforum.com/t/fill-a-list-after-enum-each-loo-p/47277 "2022-04-18T20:59:35Z")

</div>

I’m trying to fill a list from the result of many loops (iterating another list) but the result is always empty here is my code : list\_a = \[\] list\_b = \[\] Enum.each(list\_c, fn(item) -\> {item\_a, item\_b}…

---

## [Optimize function: find and update/replace in list of maps](https://forum.elixirforum.com/t/optimize-function-find-and-update-replace-in-list-of-maps/45155)

<div class="topic-metadata">

**Author:** [@josefrichter](https://forum.elixirforum.com/u/josefrichter)\
**Replies:** 7\
**Last updated:** [January 12, 2022, 11:59am UTC](https://forum.elixirforum.com/t/optimize-function-find-and-update-replace-in-list-of-maps/45155 "2022-01-12T11:59:15Z")

</div>

I have this list of maps (or structs) and I get a list of newly updated maps. I want to update the maps in the old list with the values from the new list. Basically I can just replace the old ones with the new ones (in m…

---

## [Is there a functional way to implement this idea?](https://forum.elixirforum.com/t/is-there-a-functional-way-to-implement-this-idea/44348)

<div class="topic-metadata">

**Author:** [@Stewart](https://forum.elixirforum.com/u/Stewart)\
**Replies:** 19\
**Last updated:** [December 9, 2021, 8:10pm UTC](https://forum.elixirforum.com/t/is-there-a-functional-way-to-implement-this-idea/44348 "2021-12-09T20:10:25Z")

</div>

Given a list \[0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 1\] I want to return a list containing \[3, 4, 3, 2\] ie count the number of consecutive elements that are the same. I can’t seem to figure out a good way to do this in a pu…

---

## [Suggestion for improving code to get dynamic user form outputs](https://forum.elixirforum.com/t/suggestion-for-improving-code-to-get-dynamic-user-form-outputs/42042)

<div class="topic-metadata">

**Author:** [@shahryarjb](https://forum.elixirforum.com/u/shahryarjb)\
**Replies:** 1\
**Last updated:** [August 31, 2021, 6:31pm UTC](https://forum.elixirforum.com/t/suggestion-for-improving-code-to-get-dynamic-user-form-outputs/42042 "2021-08-31T18:31:59Z")

</div>

Hi, I need your suggestion to improve my code. I need to get user dynamic form outputs and convert it to map. my user inputs: %{ "\_csrf\_token" =\> "CODE", "input-name-1" =\> "filed1", "input-name-2" =\> "field", …

---

## [How to create pagination for a list (get elements from a range of GenServer)](https://forum.elixirforum.com/t/how-to-create-pagination-for-a-list-get-elements-from-a-range-of-genserver/41506)

<div class="topic-metadata">

**Author:** [@shahryarjb](https://forum.elixirforum.com/u/shahryarjb)\
**Replies:** 4\
**Last updated:** [August 10, 2021, 7:23pm UTC](https://forum.elixirforum.com/t/how-to-create-pagination-for-a-list-get-elements-from-a-range-of-genserver/41506 "2021-08-10T19:23:39Z")

</div>

Hi, I have a big list in my GenServer which I want to load them as a pagination, for example I counted it and I have x records and I want to load it with a page size (like 20). my user inputs: page 1 and this pagination…

---

## [How to pass data from eex template to socket.js file](https://forum.elixirforum.com/t/how-to-pass-data-from-eex-template-to-socket-js-file/41169)

<div class="topic-metadata">

**Author:** [@sam007](https://forum.elixirforum.com/u/sam007)\
**Replies:** 0\
**Last updated:** [July 21, 2021, 5:16pm UTC](https://forum.elixirforum.com/t/how-to-pass-data-from-eex-template-to-socket-js-file/41169 "2021-07-21T17:16:18Z")

</div>

I have chat message app where each chat message has view reply button and message id as argument , I just want to pass that value to socket js file so that from there I can send event to backend \<button id="view\_reply"…

[Next page](https://forum.elixirforum.com/tag/list/1210.md?match_all_tags=true&page=1&tags%5B%5D=list)
