list slicing question
|
11-23-2022, 02:55 PM
Post: #1
|
|||
|
|||
list slicing question
I wanted to translate XCas code to HP Prime Cas, and have problem translate a[::n]
XCas> range(7)[::2] → [0, 2, 4, 6] Here, XCas behave like Python: >>> range(7)[::2] [0, 2, 4, 6] >>> range(7)[0:None:2] # explicitly showing defaults [0, 2, 4, 6] HP Prime Cas, however, is 1 based. (list last index has unintuitive -1 + 1 = 0) CAS> range(7)[::2] --> range(7)[1:0:2] --> [0,2,4] Is there an equivalent to Python's None ? |
|||
11-24-2022, 12:04 AM
Post: #2
|
|||
|
|||
RE: list slicing question
By trial and error, this seems to work, but weird, with 1 = beyond end-of-list
CAS> range(7)[1:1:2] → [0,2,4,6] CAS> range(7)[2:1:2] → [1,3,5] CAS> range(7)[3:1:2] → [2,4,6] |
|||
11-24-2022, 11:32 AM
Post: #3
|
|||
|
|||
RE: list slicing question | |||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 2 Guest(s)