iterable

Python: map in place

I was wondering if there is a way to run map on something. The way map works is it takes an iterable and applies a function to each item in that iterable producing a list. Is there a way to have map modify the iterable object itself? ...

Django filter bool not iterable

I want to filter all Relation Objects where (relation= following relation in a virtual community) the date one has initiated the following is in the past, related to the moment now. The following declaration seems to be wrong, as a bool object is not iterable. Is there another way to do that? d = Relations.objects.filter(date_follow < ...

Expose __main__

Hi everybody, is this legal in python?. Seems to work ... Thanks # with these lines you not need global variables anymore if __name__ == '__main__': import __main__ as main else: main = __import__(os.path.basename(os.path.splitext(__file__))) var_in_main = 0 # now any var is a global var, you can access any var from every...

How to Create a Method that only accepts elements that implement Iterable

I want to write a function printAll(), which accepts only those elements that implement that implement Iterable so that I can iterate over them and print the elements. How do I do that? ...

Porting new Iterable{} code from Scala 2.7.7 to 2.8

I saw this thread: http://stackoverflow.com/questions/1243794/what-are-the-biggest-differences-between-scala-2-8-and-scala-2-7 It seems to cover some changes, but the first compile problems I've hit don't seem to be mentioned. Any suggestions? kinds of the type arguments (Iterable[Any] with (A with Int) => Any) do not conform to the...

Check if all values of iterable are zero

Is there a good, succinct/built-in way to see if all the values in an iterable are zeros? Right now I am using all() with a little list comprehension, but (to me) it seems like there should be a more expressive method. I'd view this as somewhat equivalent to a memcmp() in C. values = (0, 0, 0, 0, 0) # Test if all items in values tuple...

Creating an O(1)-memory Iterable from an initial object and a function which generates the next object, in Scala

I want a convenient way to generate an Iterable, given a initial object and a function to produce the next object from the current one, that consumes O(1) memory (i.e., it doesn't cache old results; if you want to iterate a second time, the function has to be applied again). It doesn't seem like there's library support for this. In Scal...

LinkedList implementation in Java with generics and enhanced for

Hi. I need you to review my implementation of a Singly Linked List (SLL) please. The implementation should use generics and be able to use the enhanced for. The problem is that, when I do for (Number n : list) being list a MyLinkedList<Integer> or MyLinkedList<Double>, I get the error: "Type mismatch: cannot convert from element type O...

Java: why are iterators not copyable

I would think that Iterator.copy() would be quite a handy function. You could implement iterator filters in a much better way. For example, the only reason in Googles Java Collection for the filter (and similar) functions to use UnmodifiableIterator (which is just an Iterator without remove) is because you cannot implement such a filter...

Java: why does Collection.addAll can not accept Iterables?

Hi, I wonder why the Collection.addAll() method only accepts other Collections but not Iterables. Why is that? Any similar method to do that for Iterables? ...

Python filter / max combo - checking for empty iterator

(Using Python 3.1) I know this question has been asked many times for the general question of testing if iterator is empty; obviously, there's no neat solution to that (I guess for a reason - an iterator doesn't really know if it's empty until it's asked to return its next value). I have a specific example, however, and was hoping I ca...

"Iterable<Element> cannot be cast to List<Element>" - Isn't `List` a type of `Iterable`?

I called a getElements method which returns Iterable<Element>. I did this: List<Element> elements = (List<Element>) getElements(); This generates the error: java.lang.ClassCastException: com.utesy.Element$3 cannot be cast to java.util.List I thought a List was a type of Iterable? ...

Python: how to add contents of iterable to set?

In Python, what is the "one [...] obvious way" to add all items of an iterable to an extant set? ...