# Filter() drop elements of a tuple with singleton doesn't work

**URL:** <https://discourse.julialang.org/t/filter-drop-elements-of-a-tuple-with-singleton-doesnt-work/32896>\
**Category:** General Usage\
**Tags:** announcement\
**Created:** [January 2, 2020, 9:00pm UTC](https://discourse.julialang.org/t/filter-drop-elements-of-a-tuple-with-singleton-doesnt-work/32896 "2020-01-02T21:00:30Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Albert\_Zevelev](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/albert_zevelev/32/11844_2.png) [@Albert\_Zevelev](https://discourse.julialang.org/u/Albert_Zevelev)\
**Post date:** [January 2, 2020, 9:00pm UTC](https://discourse.julialang.org/t/filter-drop-elements-of-a-tuple-with-singleton-doesnt-work/32896/1 "2020-01-02T21:00:30Z")

</div>

I want to remove some models in tuple “dropm”, from a list of models “mList”.  
This fails when the tuple “dropm” is a singleton. It only works if “dropm” is a Vector{string}.  
I want it to work if “dropm” is a tuple.

> mList =[“m1”, “m2”, “m3”, “m4”]
> 
> # 
> 
> dropm = (“m2”, “m1”)  
> mListNew = filter(m → m ∉ dropm, mList)
> 
> # 
> 
> dropm = (“m2”)  
> mListNew = filter(m → m ∉ dropm, mList) #error
> 
> ### 
> 
> # 
> 
> dropm = [“m2”, “m1”]  
> mListNew = filter(m → m ∉ dropm, mList)
> 
> # 
> 
> dropm = [“m2”]  
> mListNew = filter(m → m ∉ dropm, mList)

---

<div class="post-metadata">

**Author:** ![oheil](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oheil/32/220745_2.png) [@oheil](https://discourse.julialang.org/u/oheil)\
**Post date:** [January 2, 2020, 9:11pm UTC](https://discourse.julialang.org/t/filter-drop-elements-of-a-tuple-with-singleton-doesnt-work/32896/2 "2020-01-02T21:11:53Z")

</div>

```julia
mList =["m1", "m2", "m3", "m4"]

dropm = ("m2", "m1")
mListNew = filter(m -> m ∉ dropm, mList)

dropm = ("m2")
mListNew = filter(m -> m ∉ dropm, mList) #ERROR

dropm = ["m2", "m1"]
mListNew = filter(m -> m ∉ dropm, mList)

dropm = ["m2"]
mListNew = filter(m -> m ∉ dropm, mList)

```

I don’t have a solution, only some better formation 🙂

---

<div class="post-metadata">

**Author:** ![simeonschaub](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/simeonschaub/32/216566_2.png) [@simeonschaub](https://discourse.julialang.org/u/simeonschaub)\
**Post date:** [January 2, 2020, 9:39pm UTC](https://discourse.julialang.org/t/filter-drop-elements-of-a-tuple-with-singleton-doesnt-work/32896/3 "2020-01-02T21:39:30Z")

</div>

`dropm = (“m2”)` is not creating a tuple, the brackets don’t do anything here, so `dropm` is just the string `"m2"`. You are probably looking for `dropm = (“m2”,)`. The comma is necessary here, since otherwise this can’t be distinguished from brackets only used for precedence like in `(1 + 2) * 3`, for example.

---

<div class="post-metadata">

**Author:** ![Albert\_Zevelev](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/albert_zevelev/32/11844_2.png) [@Albert\_Zevelev](https://discourse.julialang.org/u/Albert_Zevelev)\
**Post date:** [January 2, 2020, 9:57pm UTC](https://discourse.julialang.org/t/filter-drop-elements-of-a-tuple-with-singleton-doesnt-work/32896/4 "2020-01-02T21:57:24Z")

</div>

Thank you @simeonschaub!  
Then there is a slight generality annoyance.  
To make a vector of strings, the syntax is identical whether it is a singleton or not:

```nohighlight
dropm = ["m2", "m1"] #= VS =# dropm = ["m2"]

```

But to make a tuple, the syntax is different when the tuple is a singleton:

```nohighlight
dropm = ("m2", "m1") #= VS =# dropm =("m2",)

```

Not ideal. Already caused my code to break.

---

<div class="post-metadata">

**Author:** ![simeonschaub](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/simeonschaub/32/216566_2.png) [@simeonschaub](https://discourse.julialang.org/u/simeonschaub)\
**Post date:** [January 2, 2020, 10:06pm UTC](https://discourse.julialang.org/t/filter-drop-elements-of-a-tuple-with-singleton-doesnt-work/32896/5 "2020-01-02T22:06:39Z")

</div>

I understand the frustration, but there’s not really anything that can be done here. Like I explained above, in a case like `(1 + 2) * 3` it would otherwise be ambiguous, whether you mean a tuple containing only `3` or simply the integer `3` times `3`, since brackets can also be used just to establish mathematical precedence, e.g. which function should be evaluated first.

---

<div class="post-metadata">

**Author:** ![Albert\_Zevelev](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/albert_zevelev/32/11844_2.png) [@Albert\_Zevelev](https://discourse.julialang.org/u/Albert_Zevelev)\
**Post date:** [January 2, 2020, 10:08pm UTC](https://discourse.julialang.org/t/filter-drop-elements-of-a-tuple-with-singleton-doesnt-work/32896/6 "2020-01-02T22:08:35Z")

</div>

For math using parentheses totally makes sense. It’s the natural thing (PEMDAS).  
But for tuples w/ strings? meh. Thanks for your help though.

---

<div class="post-metadata">

**Author:** ![simeonschaub](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/simeonschaub/32/216566_2.png) [@simeonschaub](https://discourse.julialang.org/u/simeonschaub)\
**Post date:** [January 2, 2020, 10:13pm UTC](https://discourse.julialang.org/t/filter-drop-elements-of-a-tuple-with-singleton-doesnt-work/32896/7 "2020-01-02T22:13:59Z")

</div>

I think that would be much more confusing than the current behavior. The way syntax is parsed shouldn’t really depend on any type information. Otherwise it would be really hard to explain to people, why `("a")` is completely different to `(2)`. You can also just as well use infix operators with strings, so in expressions like `("a" * "b")^3`, the brackets still have an important purpose.

---

<div class="post-metadata">

**Author:** ![Albert\_Zevelev](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/albert_zevelev/32/11844_2.png) [@Albert\_Zevelev](https://discourse.julialang.org/u/Albert_Zevelev)\
**Post date:** [January 2, 2020, 10:16pm UTC](https://discourse.julialang.org/t/filter-drop-elements-of-a-tuple-with-singleton-doesnt-work/32896/8 "2020-01-02T22:16:22Z")

</div>

Thanks, I’m new to Julia & never knew about those string operations.
