# How to translate this phyton code to julia with efficienty(short code,easy to read write)? What about a append!() symbol in julia to "concatenate" vector?

**URL:** <https://discourse.julialang.org/t/how-to-translate-this-phyton-code-to-julia-with-efficienty-short-code-easy-to-read-write-what-about-a-append-symbol-in-julia-to-concatenate-vector/18036>\
**Category:** General Usage\
**Tags:** question, proposal\
**Created:** [November 26, 2018, 8:49pm UTC](https://discourse.julialang.org/t/how-to-translate-this-phyton-code-to-julia-with-efficienty-short-code-easy-to-read-write-what-about-a-append-symbol-in-julia-to-concatenate-vector/18036 "2018-11-26T20:49:56Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![rapasite](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rapasite/32/3719_2.png) [@rapasite](https://discourse.julialang.org/u/rapasite)\
**Post date:** [November 26, 2018, 8:49pm UTC](https://discourse.julialang.org/t/how-to-translate-this-phyton-code-to-julia-with-efficienty-short-code-easy-to-read-write-what-about-a-append-symbol-in-julia-to-concatenate-vector/18036/1 "2018-11-26T20:49:56Z")

</div>

Hi I was thinking this kind of code is short and easy to write is there any ways to do this in Julia? thanks

```julia
#Python code of Trinomial triangle
row = [1]
for i in range(8):
    print(row)
    row = [sum(t) for t in zip([0,0]+row, [0]+row+[0], row+[0,0])]

#output

[1]
[1, 1, 1]
[1, 2, 3, 2, 1]
[1, 3, 6, 7, 6, 3, 1]
[1, 4, 10, 16, 19, 16, 10, 4, 1]
[1, 5, 15, 30, 45, 51, 45, 30, 15, 5, 1]
[1, 6, 21, 50, 90, 126, 141, 126, 90, 50, 21, 6, 1]
[1, 7, 28, 77, 161, 266, 357, 393, 357, 266, 161, 77, 28, 7, 1]

```

Thanks you

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [November 26, 2018, 8:57pm UTC](https://discourse.julialang.org/t/how-to-translate-this-phyton-code-to-julia-with-efficienty-short-code-easy-to-read-write-what-about-a-append-symbol-in-julia-to-concatenate-vector/18036/2 "2018-11-26T20:57:25Z")

</div>

For a direct translation:

```julia
julia> row = [1]
1-element Array{Int64,1}:
 1

julia> for i in 1:8
           println(row)
           global row = [sum(t) for t in zip([0; 0; row], [0; row; 0], [row; 0; 0])]
       end
[1]
[1, 1, 1]
[1, 2, 3, 2, 1]
[1, 3, 6, 7, 6, 3, 1]
[1, 4, 10, 16, 19, 16, 10, 4, 1]
[1, 5, 15, 30, 45, 51, 45, 30, 15, 5, 1]
[1, 6, 21, 50, 90, 126, 141, 126, 90, 50, 21, 6, 1]
[1, 7, 28, 77, 161, 266, 357, 393, 357, 266, 161, 77, 28, 7, 1]

```

---

<div class="post-metadata">

**Author:** ![rapasite](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rapasite/32/3719_2.png) [@rapasite](https://discourse.julialang.org/u/rapasite)\
**Post date:** [November 26, 2018, 9:03pm UTC](https://discourse.julialang.org/t/how-to-translate-this-phyton-code-to-julia-with-efficienty-short-code-easy-to-read-write-what-about-a-append-symbol-in-julia-to-concatenate-vector/18036/3 "2018-11-26T21:03:47Z")

</div>

Thanks you, I didn’t think about the [;;] notation, I am not use to it.  
I was thinking to much about the python strange “[1]+[0] = [1,0]”.  
Have a nice day

---

<div class="post-metadata">

**Author:** ![rapasite](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rapasite/32/3719_2.png) [@rapasite](https://discourse.julialang.org/u/rapasite)\
**Post date:** [November 26, 2018, 9:18pm UTC](https://discourse.julialang.org/t/how-to-translate-this-phyton-code-to-julia-with-efficienty-short-code-easy-to-read-write-what-about-a-append-symbol-in-julia-to-concatenate-vector/18036/4 "2018-11-26T21:18:08Z")

</div>

Is there any reason for not having a symbol in Julia who work like + and vectors in python? I mean a symbol who does the same has appends!()?

Julia have the \* for strings.

Thank you

---

<div class="post-metadata">

**Author:** ![GunnarFarneback](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gunnarfarneback/32/1827_2.png) [@GunnarFarneback](https://discourse.julialang.org/u/GunnarFarneback)\
**Post date:** [November 26, 2018, 9:45pm UTC](https://discourse.julialang.org/t/how-to-translate-this-phyton-code-to-julia-with-efficienty-short-code-easy-to-read-write-what-about-a-append-symbol-in-julia-to-concatenate-vector/18036/5 "2018-11-26T21:45:23Z")

</div>

> [@rapasite](#):
>
> Is there any reason for not having a symbol in Julia who work like + and vectors in python? I mean a symbol who does the same has appends!()?

Here is some reading on that subject: [RFC: deprecate \* in favor of new ++ concatenation operator by stevengj · Pull Request #22461 · JuliaLang/julia · GitHub](https://github.com/JuliaLang/julia/pull/22461)

---

<div class="post-metadata">

**Author:** ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)\
**Post date:** [November 26, 2018, 9:47pm UTC](https://discourse.julialang.org/t/how-to-translate-this-phyton-code-to-julia-with-efficienty-short-code-easy-to-read-write-what-about-a-append-symbol-in-julia-to-concatenate-vector/18036/6 "2018-11-26T21:47:43Z")

</div>

Consistency with mathematics. In mathematics, `+` on vectors doesn’t append them, it adds them as vectors. I.e. `[1,2,3] + [2,3,4] == [3,5,7]` rather than `[1,2,3] + [2,3,4] == [1,2,3,2,3,4]`.

---

<div class="post-metadata">

**Author:** ![rapasite](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rapasite/32/3719_2.png) [@rapasite](https://discourse.julialang.org/u/rapasite)\
**Post date:** [November 26, 2018, 9:54pm UTC](https://discourse.julialang.org/t/how-to-translate-this-phyton-code-to-julia-with-efficienty-short-code-easy-to-read-write-what-about-a-append-symbol-in-julia-to-concatenate-vector/18036/7 "2018-11-26T21:54:43Z")

</div>

What about using another symbol witch is not + or \*?

I guess [a;b] is still concise and work perfectly fine.

Thanks

---

<div class="post-metadata">

**Author:** ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)\
**Post date:** [November 26, 2018, 11:29pm UTC](https://discourse.julialang.org/t/how-to-translate-this-phyton-code-to-julia-with-efficienty-short-code-easy-to-read-write-what-about-a-append-symbol-in-julia-to-concatenate-vector/18036/8 "2018-11-26T23:29:16Z")

</div>

> [@rapasite](#):
>
> What about using another symbol witch is not + or \*?

You mean like `++`?

---

<div class="post-metadata">

**Author:** ![rapasite](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rapasite/32/3719_2.png) [@rapasite](https://discourse.julialang.org/u/rapasite)\
**Post date:** [November 27, 2018, 1:58am UTC](https://discourse.julialang.org/t/how-to-translate-this-phyton-code-to-julia-with-efficienty-short-code-easy-to-read-write-what-about-a-append-symbol-in-julia-to-concatenate-vector/18036/9 "2018-11-27T01:58:11Z")

</div>

I was speaking about any symbol really if it is not use yet in the language for other things.

I find it very nice that you use ∪ for union and ∩ for intersect for example.

Maybe there is a symbol out there who can suggest this append!() function.

But really this is not a big deal , I think the [;;;] syntax is working fine , I just forgot about it for a moment there.

---

<div class="post-metadata">

**Author:** ![Jean\_Michel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jean_michel/32/8282_2.png) [@Jean\_Michel](https://discourse.julialang.org/u/Jean_Michel)\
**Post date:** [November 27, 2018, 10:52am UTC](https://discourse.julialang.org/t/how-to-translate-this-phyton-code-to-julia-with-efficienty-short-code-easy-to-read-write-what-about-a-append-symbol-in-julia-to-concatenate-vector/18036/10 "2018-11-27T10:52:18Z")

</div>

About what is desirable to write:

```julia
julia> row=[1]
1-element Array{Int64,1}:
 1

julia> @btime [0;0;$row]
  2.716 μs (28 allocations: 1.13 KiB)
3-element Array{Int64,1}:
 0
 0
 1

julia> @btime [[0,0];$row]
  57.540 ns (2 allocations: 208 bytes)
3-element Array{Int64,1}:
 0
 0
 1

```

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [November 27, 2018, 1:56pm UTC](https://discourse.julialang.org/t/how-to-translate-this-phyton-code-to-julia-with-efficienty-short-code-easy-to-read-write-what-about-a-append-symbol-in-julia-to-concatenate-vector/18036/11 "2018-11-27T13:56:01Z")

</div>

The difference is

```julia
julia> @btime vcat(0, 0, $[1])
  2.921 μs (28 allocations: 1.13 KiB)
3-element Array{Int64,1}:
 0
 0
 1

julia> @btime vcat([0, 0], $[1])
  81.220 ns (2 allocations: 208 bytes)
3-element Array{Int64,1}:
 0
 0
 1

```

I think that there is a fast path for `vcat` with only `Array` arguments.
