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
extraction with [:]
Modérateur : xcasadmin
-
- Messages : 562
- Inscription : sam. févr. 04, 2017 11:34 pm
- Localisation : Colombia
- Contact :
Re: extraction with [:]
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.
a[6:0:-2] will return a non empty list only if a has size>=7.
-
- Messages : 562
- Inscription : sam. févr. 04, 2017 11:34 pm
- Localisation : Colombia
- Contact :
Re: extraction with [:]
. =(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"]
-
- Messages : 562
- Inscription : sam. févr. 04, 2017 11:34 pm
- Localisation : Colombia
- Contact :
Re: extraction with [:]
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]
[1].extend([2]) [enter] [1,2]
so the following should work.
a:=[9,8,7]
a[:2].extend(a[2:]) [enter]
[9,8,7]