Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Introduction to Python List Comprehensions
#6
(02-18-2010, 09:45 PM)uber1337 Wrote: map/filter equivalent:
Code:
sum = []
for x in range(1000):
    sum.append(x)
sum = filter(lambda x : x % 3 == 0 or x % 5 == 0, sum)
sum = reduce(lambda x, y: x + y, sum)
print sum
Yep. Your way is better ;)

Edit:
One liner FTW!
Code:
reduce(lambda x,y : x+y, [x for x in xrange(1000) if x % 3 == 0 or x % 5 == 0])

Lol, you and your lambda bologna Tongue
[Image: nv70ad.png]
Terrorcore, unleash, extermination
Hyper real, cold blood, determination
fudge them, I like this sensation
Incredible, I from the annihilation
Reply


Messages In This Thread
RE: Introduction to Python List Comprehensions - by Fallen - 04-05-2010, 05:57 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Python Help Dεlluzion 3 2,028 09-30-2019, 12:59 AM
Last Post: samsmith001
  Simple Python Python Compiler Canoris 21 9,345 06-01-2011, 06:30 PM
Last Post: Filefinder
  Python 2 vs 3? Jake 8 2,719 12-11-2010, 04:13 PM
Last Post: Bursihido
  Python help Kharnage 2 925 02-12-2010, 09:07 PM
Last Post: Kharnage
  "==" and "is" in Python Canoris 1 858 02-07-2010, 03:55 PM
Last Post: uber1337

Forum Jump:


Users browsing this thread: 3 Guest(s)