# Fun One Liners

**URL:** <https://discourse.julialang.org/t/fun-one-liners/28352>\
**Category:** General Usage\
**Created:** [September 3, 2019, 11:13pm UTC](https://discourse.julialang.org/t/fun-one-liners/28352 "2019-09-03T23:13:18Z")\
**Posts on this page:** 1\
**Showing post:** 134

<div class="post-metadata">

**Author:** ![Dan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dan/32/42581_2.png) [@Dan](https://discourse.julialang.org/u/Dan)\
**Post date:** [October 12, 2022, 4:26pm UTC](https://discourse.julialang.org/t/fun-one-liners/28352/134 "2022-10-12T16:26:11Z")

</div>

The goal of the code is to get the “first and last number in a sequence of consecutive numbers”, or by example, from:

```julia
df = DataFrame([]) 
df.list = [[1,2,3,6,12,13,14],[20,21,23,24,50],[1,3,5,7,10,11,12,13]]

```

to add the following field:

```julia
df.new = [[1,3,12,14],[20,21,23,24],[10,13]] #it is important that they are made up of pairs!

```

Various solutions with better run-time are shown in thread:  
[https://discourse.julialang.org/t/how-to-reduce-redundancy-in-a-list-inside-a-dataframe/88585](https://discourse.julialang.org/t/how-to-reduce-redundancy-in-a-list-inside-a-dataframe/88585)  
But a neat one-line solution is:

```julia
transform(df, :list => ByRow(f->filter(x->(x-1 ∈ f) ⊻ (x+1 ∈ f),f)) => :new)

```

Kudos to @rafael.guerra for pointing me to this thread.

---

_[View the full topic](https://discourse.julialang.org/t/fun-one-liners/28352)._
