Fork me on GitHub
#clojure-uk
<
2021-07-16
>
dharrigan06:07:25

Good Morning!

djm06:07:22

Second 💉 at lunchtime today

👍 4
dharrigan13:07:28

anyone good with python here?

Aron13:07:23

no, but i am interested with lots of free time currently

folcon13:07:19

@dharrigan pretty good, what do you need?

dharrigan13:07:01

Sya you have a list containing a series of maps

dharrigan13:07:06

I have something like:

dharrigan13:07:15

for s in c.get('foo', [])

dharrigan13:07:31

if s.get('bar') == baz....

dharrigan13:07:36

can I condense that?

folcon13:07:25

You're trying to write a comprehension right?

folcon13:07:19

Are the dict values lists? Also don't use .get('bar') use .get('bar', None)

folcon13:07:36

.get('bar') will throw an exception

Aron14:07:17

seems like nested equality check

Conor15:07:14

You can use Python's unpleasant (IMO) list comprehensions to do this: f = [x for x in c if x.get('bar', None) == 'baz']

dharrigan15:07:26

I had some helpful pointers from @folcon on a DM. So all good 🙂

Aron15:07:45

what's the last version, i am curious 🙂

Aron16:07:30

i probably would've went for filtering and then doing a simple == on the full thing

dharrigan18:07:16

For my use case, using the for and if is fine 🙂

Aron19:07:02

🙂 usually is