GAMS to GAMSPy dynamic sets

Hello! I am trying to translate my code from GAMS to GAMSPy. My main problem is the dynamic sets which in GAMS are defined by dollar statements and loop statements. Is there any example that might of help to understand the logic to efficiently make the translation? Here is my GAMS code:

Tb(t)$(ord(t)<(card(t)/2))=yes;
Tl(t)$(ord(t)>(card(t)/2))=yes;
Tl_even(t)$((mod(ord(t),2)=0)and(Tl(t)))=yes;
Tl_odd(t)$((mod(ord(t),2)=1)and(Tl(t)))=yes;
U(k)$(Ord(k)>=5)=yes;
subT(t)=yes;
Parent(t,tt)$(2*ord(t)=ord(tt))=yes;
Parent(t,tt)$(2*ord(t)+1=ord(tt))=yes;
tB(t)$((ord(t)<(card(subT)/2))and(subT(t)))=yes;
tL(t)$((ord(t)>(card(subT)/2))and(subT(t)))=yes;
loop(t,
         loop(tt,
                 anc(t,tt)$(2*ord(t)=ord(tt))=yes;
                 anc(t,tt)$(2*ord(t)+1=ord(tt))=yes;
                 ));
loop((t,tt),
         Tree(t,tt,"left")$((mod(ord(tt),2) = 0)and(anc(t,tt)))=yes ;
         Tree(t,tt,"right")$((mod(ord(tt),2) = 1)and(anc(t,tt)))=yes ;
         );

loop(t,
         loop(tt,
                 loop(ttt,
                         anc(t,ttt)$((anc(t,tt))and(anc(tt,ttt))) =yes;
                         )));

Right(t)$(mod(ord(t),2) = 1)=yes;
Left(t)$(mod(ord(t),2) = 0)=yes;


loop((t,tt,ttt),
         path(t,ttt,dd)$((Tree(t,tt,dd))and(anc(tt,ttt))and(anc(t,ttt)))=yes;) ;
         path(t,tt,dd)$Tree(t,tt,dd)=yes;

We have an examples repository with more than a hundred models: https://github.com/GAMS-dev/gamspy-examples. The equivalent of $ in GAMS is .where in GAMSPy.

For example, your first line could be written as:

Tb[t].where[Ord(t) < (Card(t) / 2)] = True

For loops, you can use regular Python loops. You can check the tsp4 as an example for loops.