Author Topic: List Indexing and Slicing.  (Read 938 times)

0 Members and 1 Guest are viewing this topic.

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2145
  • class keyThumper<T>:ILazy<T>
List Indexing and Slicing.
« on: February 02, 2022, 02:24:01 PM »
Was reminded by the current challenges how often I've thought how nice it would be to have
list Indexing and Slicing based on the index location:
eg:
https://railsware.com/blog/python-for-machine-learning-indexing-and-slicing-for-lists-tuples-strings-and-other-sequential-types/
Code - Python: [Select]
  1. >>> nums = [10, 20, 30, 40, 50, 60, 70, 80, 90]
  2. >>> nums[0:4]
  3. [10, 20, 30, 40]
  4.  
  5. >>> nums[::2]
  6. [10, 30, 50, 70, 90]
  7.  
  8. >>> some_nums = nums[2:7]
  9. >>> some_nums
  10. [30, 40, 50, 60, 70]
  11.  
  12. >>> nums[-3:]
  13. [70, 80, 90]
  14.  

anyone played with this concept ??
Called Kerry in my other life
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.

JohnK

  • Administrator
  • Seagull
  • Posts: 10653
Re: List Indexing and Slicing.
« Reply #1 on: February 02, 2022, 03:40:40 PM »
Reminds me so much of arrays. :) And so far, we have covered a few of those. In the "challenge queue" we have a few challenges that, combined, will give a bit more `array like' flavor. Great link.

Two of the items I miss most, from other languages, are pointers and arrays.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

d2010

  • Bull Frog
  • Posts: 326
Re: List Indexing and Slicing.
« Reply #2 on: February 03, 2022, 02:27:12 PM »
Was reminded by the current challenges how often I've thought how nice it would be to have
list Indexing and Slicing based on the index location:
eg:
The main problem is = I not found fast index, because, I feel
assoc(1,list(...)) is too slow.
If you need then I need help, together can emulate JavaIndexer inside
or MoreMathematicallyLisp inside
Code: [Select]
(defun dfn_view_pnts(ljfour / $rr a b c d e f x)
/*c2s: b=getvar("VIEWSIZE"),
       $rr=getvar("SCREENSIZE"),
       c=car($rr),
       d=cadr($rr),
       a=b*c/d,
       x=getvar(_T("VIEWCTR")),
       x=trans(x,1,2);
       c=list( car(x)-(a/2.0),cadr(x)-(b/2.0),0.0),
       d=list( car(x)+(a/2.0),cadr(x)+(b/2.0),0.0),
       c=trans(c,2,1),
       d=trans(d,2,1),
       $rr=(ljfour)?list(c,list(car(c),cadr(d),0.0),list(cadr(c),car(d),0.0),d):
           (ljfour==4)?list(c,list(car(c),cadr(d),0.0),list(cadr(c),car(d),0.0),d):
           list(c,d);
*/
$rr)