![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#21 |
|
Hobbyist Programmer
Join Date: Jun 2006
Posts: 137
Rep Power: 0
![]() |
It was a joke but I guess by the way people posted back about it, it didn't turn out that way. Calm down and don't be like 25% of the rest of the community here and jump on someones back becouse of a post that THE READER took the wrong way.
|
|
|
|
|
|
#22 |
|
Expert Programmer
|
Thanks for the tips, Cerulean.
The final function I ended up writing executed almost instantly when given a 12-digit number, as opposed to the previous function, which took over a minute. In case anyone's interested, this problem came from a USACO challege; now I have to re-write it in C++ or Java in order to submit it. (I wrote in Python to get experience with the language.) If anyone knows of a site with Python-specific challenges, I would be very interested... Last edited by titaniumdecoy; Jun 9th, 2006 at 7:04 PM. |
|
|
|
|
|
#23 |
|
Professional Programmer
Join Date: Feb 2005
Posts: 434
Rep Power: 4
![]() |
Just to warn you, both filter() and map() will go away with Python3. As Arevos pointed out, they can be easily replaced with list comprehensions:
# write your own using list comprehension:
def map(f, s):
return [f(x) for x in s]
def filter(f, s):
return [x for x in s if f(s)]
__________________
I looked it up on the Intergnats! |
|
|
|
|
|
#24 |
|
Programming Guru
![]() Join Date: Apr 2005
Posts: 1,799
Rep Power: 5
![]() |
I find it quite silly how Python3 decided to add things like "any()" and "all()" when they are even easier to make yourself then the functions they are taking away ("filter()", "map()").
|
|
|
|
|
|
#25 | |
|
Professional Programmer
Join Date: Feb 2005
Posts: 434
Rep Power: 4
![]() |
Quote:
I think filter() and map() were introduced to Python before list comprehension came around. List comprehension is probably more efficient, particularly if you use the corresponding generator.
__________________
I looked it up on the Intergnats! |
|
|
|
|
|
|
#26 | ||
|
Professional Programmer
Join Date: Apr 2005
Location: London, England
Posts: 459
Rep Power: 4
![]() |
Quote:
l = [104, 101, 108, 108, 111] map(chr, l) # faster than [chr(x) for x in l] as the actual looping for the map function is done in C [(x > 105) for x in l] # faster than map(lambda x: x > 105, l) because calling a function is fairly costly in Python. Quote:
def map(func, l):
return [func(x) for x in l]
def filter(func, l):
return [x for x in l if func(x)] |
||
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|