list slicing question - Printable Version +- HP Forums (https://www.hpmuseum.org/forum) +-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html) +--- Forum: HP Prime (/forum-5.html) +--- Thread: list slicing question (/thread-19193.html) |
list slicing question - Albert Chan - 11-23-2022 02:55 PM 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 ? RE: list slicing question - Albert Chan - 11-24-2022 12:04 AM 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] RE: list slicing question - Albert Chan - 11-24-2022 11:32 AM (11-24-2022 12:04 AM)Albert Chan Wrote: By trial and error, this seems to work, but weird, with 1 = beyond end-of-list At least it is consistently weird, for 0-based XCas, 0 = beyond end-of list XCas> range(7)[0:0:2] → [0,2,4,6] XCas> range(7)[1:0:2] → [1,3,5] XCas> range(7)[2:0:2] → [2,4,6] |