generator-expression Questions
2
Solved
How can I get a callable factory for a defaultdict to allow populating it with a comprehension? I think it's probably not possible, but I can't think of a good reason why?
>>> def foo(*ar...
Guiana asked 14/1, 2014 at 0:13
6
Solved
I have this:
>>> sum( i*i for i in xrange(5))
My question is, in this case am I passing a list comprehension or a generator object to sum ? How do I tell that? Is there a general rule a...
Finance asked 13/8, 2013 at 14:42
1
Solved
On several occasions I've wanted python syntax for short-circuiting list comprehensions or generator expressions.
Here is a simple list comprehension, and the equivalent for loop in python:...
Janka asked 5/6, 2013 at 3:47
4
I am using Python to parse a large file. What I want to do is
If condition =True
append to list A
else
append to list B
I want to use generator expressions for this - to save memory. I am put...
Keelykeen asked 24/8, 2012 at 16:22
3
Solved
Possible Duplicate:
Do python's variable length arguments (*args) expand a generator at function call time?
Let's say you have a function like this:
def give_me_many(*elements):
...
Firetrap asked 16/8, 2012 at 11:59
3
Solved
I was answering this question, I preferred generator expression here and used this, which I thought would be faster as generator doesn't need to create the whole list first:
>>> lis=[['a'...
Ashur asked 15/8, 2012 at 4:29
4
Solved
In the following:
name = 'TODD'
chars = set('AEIOU')
for ii in range(-1, int(math.copysign(len(name) + 1, -1)), -1):
if any((cc in chars) for cc in name[ii]):
print 'Found'
else:
print 'Not Fo...
Laellaertes asked 26/7, 2012 at 15:27
4
Solved
In Python, is there any way to write this list comprehension without the "x in" variable (since it is left completely unused)? Same applies to a generator expression. I doubt this comes up very oft...
Grath asked 29/6, 2012 at 11:34
2
Solved
I want to determine if a list contains a certain string, so I use a generator expression, like so:
g = (s for s in myList if s == myString)
any(g)
Of course I want to inline this, so I do:
any(...
Gpo asked 15/2, 2012 at 16:56
2
Solved
I can use if and for in list comprehensions/generator expressions as
list(i for i in range(100) if i*i < 30)
I know this is not the most efficient but bear with me as the condition could be m...
Seriatim asked 31/3, 2011 at 20:27
4
print max(3 for i in range(4))
#output is 3
Using Python 2.6
The 3 is throwing me off, heres my attempt at explaining whats going on.
for i in range(4) makes a loop that loops 4 times, incremen...
Pasia asked 13/5, 2011 at 20:41
2
Solved
I was trying to find the quickest way to count the number of items in a list matching a specific filter.
In this case, finding how many odd numbers there are in a list.
While doing this, I was sur...
Terenceterencio asked 31/1, 2010 at 23:23
2
Solved
Is there, in Django, a standard way to write complex, custom filters for QuerySets?
Just as I can write
MyClass.objects.all().filter(field=val)
I'd like to do something like this :
MyClass.ob...
Speculator asked 23/3, 2009 at 3:53
3
Solved
The following test fails:
#!/usr/bin/env python
def f(*args):
"""
>>> t = 1, -1
>>> f(*map(lambda i: lambda: i, t))
[1, -1]
>>> f(*(lambda: i for i in t)) # -...
Pehlevi asked 26/9, 2008 at 14:19
© 2022 - 2024 — McMap. All rights reserved.