PacktPublishing / Deep-Reinforcement-Learning-Hands-On

Hands-on Deep Reinforcement Learning, published by Packt
MIT License
2.83k stars 1.28k forks source link

List comprehension #56

Closed StrangeTcy closed 5 years ago

StrangeTcy commented 5 years ago

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.

Shmuma commented 5 years ago

Hi!

You're right, your version is better and has the same semantics. Don't remember why I used map and list :)

пт, 23 авг. 2019 г., 17:07 Maxim Smirnov notifications@github.com:

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 corssentropy_cartpole https://github.com/PacktPublishing/Deep-Reinforcement-Learning-Hands-On/blob/master/Chapter04/01_cartpole.py 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.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/PacktPublishing/Deep-Reinforcement-Learning-Hands-On/issues/56?email_source=notifications&email_token=AAAQE2RMAWORQ2LYYOX4ZYLQF7VLFA5CNFSM4IPAA7H2YY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4HHBUT5Q, or mute the thread https://github.com/notifications/unsubscribe-auth/AAAQE2U77SLWPC5NAH6JANTQF7VLFANCNFSM4IPAA7HQ .

StrangeTcy commented 5 years ago

Ok then :-)