Unpacking of tuples of varying sizes in Julia

56 Views Asked by At

I have a python code here :

>>> a, *b , c = (1,2,3,4)
>>> a
1
>>> b
[2, 3]
>>> c
4
>>> 

Is there a similar facility available with Julia?

Same command in Julia is giving error : " * is not a unary operator"

1

There are 1 best solutions below

0
Sundar R On BEST ANSWER

You can use the ... operator for this. (Requires Julia version 1.9 or above.)

julia> a, b..., c = (1, 2, 3, 4)
(1, 2, 3, 4)

julia> a
1

julia> b
(2, 3)

julia> c
4