PacktPublishing / Deep-Reinforcement-Learning-Hands-On

Hands-on Deep Reinforcement Learning, published by Packt

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

List comprehension

StrangeTcy opened this issue · comments

Is there any specific reason you're not using list comprehensions? It seems much more "pythonic" than dealing with lists, maps and lambdas.
For example, in crossentropy_cartpole you're getting rewards from a batch like this:

def filter_batch(batch, percentile):
    rewards = list(map(lambda s: s.reward, batch))

while the same could be written as

def filter_batch(batch, percentile):
    rewards = [s.reward for s in batch]

,which (to me, anyway) looks cleaner and easier to understand.

Ok then :-)