Page 1 sur 1

extraction with [:]

Publié : jeu. avr. 25, 2019 10:42 pm
par compsystems
Hello BP

a:=["foo","bar","baz","qux","quux","corge"]
a[:4].extend(a[4:]) [enter]
".(a[0:4],extend(a[4 .. -1]))
Error: Invalid dimension"

expected
["foo","bar","baz","qux","quux","corge"]


a[0:6:2] [enter]
["foo", "baz", "quux"] # ok

a[1:6:2] [enter]
["bar", "qux", "corge"] # ok

a[6:0:-2] [enter]
[]
expected
["corge", "qux", "bar"]

a[::-1] [enter]
["corge", "quux", "qux", "baz", "bar", "foo"] # ok

Re: extraction with [:]

Publié : sam. avr. 27, 2019 9:55 am
par parisse
You can only extend a variable containing a list, not a list.
a[6:0:-2] will return a non empty list only if a has size>=7.

Re: extraction with [:]

Publié : lun. avr. 29, 2019 7:32 pm
par compsystems
You can only extend a variable containing a list, not a list
. =(

I wanted a synonym for + python operator a[:4]+(a[4:]) > a[:4].extend(a[4:]), without storing subvariables.

b:=a[:4]
b.extend(a[4:]) [enter]
b:=["foo","bar","baz","qux","quux","corge"]

Re: extraction with [:]

Publié : sam. mai 18, 2019 2:37 pm
par compsystems
The following case works well,
[1].extend([2]) [enter] [1,2]

so the following should work.
a:=[9,8,7]
a[:2].extend(a[2:]) [enter]
[9,8,7]