carlofazioli / cardiathena

A project to study strategies in the game of hearts, using distributed computing, AI, and data analytics.
GNU General Public License v3.0
6 stars 1 forks source link

Pythonic array iteration #74

Open kruzaavn opened 4 years ago

kruzaavn commented 4 years ago

We've noticed that iterating though python lists and other iterable objects the following pattern is often used

for i in range(len(iterable_object)):
    item = itterable[i]
    item.some_method()
    ...

pythonic iteration is


for item in itterable_object:
   item.some_method()
   ...

if the index of an iterable is needed use the enumerate function


for i, item in enumerate(iterable_object):
    item.some_method() 
    print(i)
    ...

for an example see base.py line 132

davidjha commented 4 years ago

So progress on the pythonic array iteration branch has halted. I think there are some good things in the branch as far as condensing some of the code, and being more pythonic. Particularly sort_suits() in lowlayer.py, but the methods are functionally the same as the one in master.

However I don't believe this is a top priority. I can continue to make conversions to the for loops, but the issue may be long lived.