dharmik

@dharmik@linuxusers.in

admin @ linuxusers.in
student. mostly computers.

matrix@spiderham:matrix.org
codeshithttps://github.com/dhrm1k
bloghttps://dhrm1k.github.io

46 following 17 followers

2 ★ 3 ↺

dharmik »
@dharmik@linuxusers.in

using list comprehension and ternary operator to print even numbers from 1 to 10. 🤯

[print(x) for x in range(1, 11) if x % 2 == 0]

...
0 ★ 0 ↺

dharmik »
@dharmik@linuxusers.in

i had no idea list comprehension existed,

thisislist = ["apple", "banana", "cherry", "kiwi", "mango"]

new_list = [i for i in thisislist if "a" in i]

print(new_list)


...

Drew »
@crmsnbleyd@hachyderm.io

@dharmik welcome to one of the funnest part of python

...

Drew »
@crmsnbleyd@hachyderm.io

@dharmik there's set and dict comprehensions as well

arialdo »
@arialdo@mastodon.online

@dharmik wait to realize that list comprehensions are syntactic sugar for monads…

...
0 ★ 0 ↺

dharmik »
@dharmik@linuxusers.in

@arialdo@mastodon.online the aha moment.

...

History