Ask HN: is it a good idea in Python? If yes, how to make it not suck?
1–10 of 11 posts
Re: Ask HN: is it a good idea in Python? If yes, how to make it not suck?
#2Re: Ask HN: is it a good idea in Python? If yes, how to make it not suck?
#3Re: Ask HN: is it a good idea in Python? If yes, how to make it not suck?
#4is what a good idea in python?
#
#Problem: all these lambdas suck. Any better ways to do it?
#
#
#TODOS/QUESTIONS:
#
#1. is it a good idea?
#
#2. can it be made to not suck (do something with all those lambdas)?Re: Ask HN: is it a good idea in Python? If yes, how to make it not suck?
#5is what a good idea in python?
From the article: # #Problem: all these lambdas suck. Any better ways to do it? # # #TODOS/QUESTIONS: # #1. is it a good idea? # #2. can it be made to not suck (do something with all those lambdas)?
It very well might be the only way to solve the issue given external constraints, but it may also be the case that, for example, reworking the problem space would lend itself to a much more elegant solution.
Code should never be treated as if it exists in some sort of bubble.
Re: Ask HN: is it a good idea in Python? If yes, how to make it not suck?
#6http://groups.google.com/group/comp.lang.python/browse_threa...
Re: Ask HN: is it a good idea in Python? If yes, how to make it not suck?
#7 table = ((8, 2, 9), (4, 5, 6), (2, 1, 9))
my_sum = sum(row[0] for row in table if row[2] == 9)
# assert my_sum == 10
my_lst = [row[0] for row in table if row[2] == 9]
# all row[2] == 9 therefore OrderBy is a no-op in your example
# assert my_lst == [8, 2]
Modified example: myLst = From(table) \
.Where(lambda column: column[2]==9) \
.OrderBy(lambda column: column[1]) \
.Select(lambda column: column[0])
my_lst = sorted((row[1], row[0]) for row in table if row[2] == 9)
my_lst = map(itemgetter(1), my_lst)
# assert my_lst == [2, 8]
Or to preserve order in case some row[1] are equal: my_lst = [row for row in table if row[2] == 9]
my_lst.sort(key=itemgetter(1)) # requires "lambda"
my_lst = [row[0] for row in my_lst]
# assert my_lst == [2, 8]Re: Ask HN: is it a good idea in Python? If yes, how to make it not suck?
#8Your examples rewritten in a different style: table = ((8, 2, 9), (4, 5, 6), (2, 1, 9)) my_sum = sum(row[0] for row in table if row[2] == 9) # assert my_sum == 10 my_lst = [row[0] for row in table if row[2] == 9] # all row[2] == 9 therefore OrderBy is a no-op in your example # assert my_lst == [8, 2] Modified example: myLst = From(table) \ .Where(lambda column: column[2]==9) \ .OrderBy(lambda column: column[1]) \ .Se…
"#LINQ in C# is cool #Python doesn't quite need it as it has generatior expressions, sum(), len(), sorted() and itertools.groupby() #so let's just wrap a nice SQL-like interface over them in order to make them more familiar"
you have trouble understanding?
I'm trying to wrap a unified and familiar SQL-like, LINQ-like interface over gen. expressions, sorted(), len() and suchlike and you remark that gen. expressions, sorted() and suchlike exist. Wow!
Re: Ask HN: is it a good idea in Python? If yes, how to make it not suck?
#9Re: Ask HN: is it a good idea in Python? If yes, how to make it not suck?
#10Earlier quoted context omitted.
From the article: # #Problem: all these lambdas suck. Any better ways to do it? # # #TODOS/QUESTIONS: # #1. is it a good idea? # #2. can it be made to not suck (do something with all those lambdas)?
Issue being that how can anyone answer those two questions without understanding the problem he/she is attempting to solve? It very well might be the only way to solve the issue given external constraints, but it may also be the case that, for example, reworking the problem space would lend itself to a much more elegant solution. Code should never be treated as if it exists in some sort of bubble.
"#LINQ in C# is cool #Python doesn't quite need it as it has generatior expressions, sum(), len(), sorted() and itertools.groupby() #so let's just wrap a nice SQL-like interface over them in order to make them more familiar." ?
It's getting the above-mentioned features as easy to use for the SQL-familiar programmer as possible.