All Questions
17 questions
1
vote
2
answers
204
views
What is the most pythonic way to exclude a special value from an iterator?
As an example. Lets say I have a grid-based game, where the player agent can walk to all squares around the current position, but not stay still.
Thus we could see each move as a tuple (dx,dy), with ...
0
votes
1
answer
386
views
Python - Filter nested inside of map produces unexpected output
I have a list of filenames (strings) and and a set ls consisting of floats. Initially I want to filter all files that match each element of ls according to a predetemined expression:
I convert all ...
0
votes
1
answer
104
views
function that takes an iterator and returns the first element in the iterator that is divisible for 2
I want to find the function that allows me to obtain an element from an iterator and returns the elements that are divisible by two or if it is not, it will print zero, however I only get it to print ...
3
votes
3
answers
129
views
Unexpected behavior with iterators
I tried to implement the sieve of Eratosthenes with iterators (because I wanted to get more into functional programming with python). Sadly some unexpected behaviour occurred. You can see it here in ...
-1
votes
2
answers
243
views
Apply operation and list to nested list
There are a large number of questions on iterating over nested lists, however I would like to iterate over a nested list and apply another list.
Here is my scenario:
def operation(a, b):
return ...
2
votes
2
answers
973
views
How to do a full outer join / merge of iterators by key?
I have multiple sorted iterators that yield keyed data, representable by lists:
a = iter([(1, 'a'), (2, 't'), (4, 'c')])
b = iter([(1, 'a'), (3, 'g'), (4, 'g')])
I want to merge them, using the key ...
0
votes
2
answers
5k
views
List comprehension for extracting re.findall matches
I have a regular expression with a single group, and I want to use it to map a list of strings to a filtered list of matches for strings that match. Currently, I'm using the following:
matches = (re....
-1
votes
1
answer
56
views
why built in function next(iter_obj) when we have method iter_obj.next() [duplicate]
I'm new to python ,and just trying to figure out why two ways? any specific reason? which one is better?
I've tried searching but not able to find it.
3
votes
1
answer
605
views
Efficient way to call multiple reduce functions on an iterable in Python?
I'd like to run several reduce functions on an iterable in Python (2.7). An example would be calling min and max on an iterable of integers. But of course you can't call reduce(min, it) and reduce(...
2
votes
1
answer
552
views
Python: Functionally Merging Two Iterators Where One is Recursive
The related question How do I merge two python iterators? works well for two independent iterators. However, I haven't been able to find or think of the tools necessary for merging two iterators ...
0
votes
1
answer
477
views
In python, how do I map an iterable to an iterable?
I have an iterable -- that is, something which responds to __iter__ and which can be iterated over lazily, multiple times using a new fresh iterator each time.
I want to map this to another iterable,...
2
votes
1
answer
2k
views
Python: compose list from nested iterators
I have a list of tuples that I need to expand it by adding two elements, each of them comes from a list. So I have [(1, 2, 3)] and two iterators it1 = (i for i in ['a1', 'a2']) and it2 = (i for i in ...
8
votes
2
answers
2k
views
Using itertools for recursive function application
I need a Python function iterate(f, x) that creates an iterator returning the values x, f(x), f(f(x)), f(f(f(x))), etc (like, e.g., Clojure's iterate). First of all, I was wondering: Does this ...
40
votes
5
answers
53k
views
Python equivalents to LINQ
In C#, with LINQ, if I have en enumeration enumerable, I can do:
// a: Does the enumerable contain an item that satisfies the lambda?
bool contains = enumerable.Any(lambda);
// b: How many items ...
4
votes
1
answer
2k
views
How to compose iterators?
I have a network of nodes passing structured data in between. For my subproblem, we have this branch - linear sequence of nodes:
nodes = [source, n1, n2, n3, n4]
First node is a generator, each other ...