If I have these two classes:
class A {}
class B : A {}
and I make a List<A> but I want to add a List<B> to it by calling List<A>.AddRange(List<B>) but the compiler refuses:
Argument '1': cannot convert from 'System.Collections.Generic.List<A>'
to 'System.Collections.Generic.IEnumerable<B>
which I completely understand because IEnum...
How can one easily iterate through all nodes in a TreeView, examine their .Checked property and then delete all checked nodes?
It seems straightforward, but you aren't supposed to modify a collection through which you are iterating, eliminating the possibility of a "foreach" loop. (The .Nodes.Remove call is modifying the collection.) ...
I want to go through all the elements on a page using Javascript and see if they have a property set. Is there an easy way to do this, or do I have to use a recursive solution?
...
I want to calculate the sum of
1/1 + 1/2 + 1/3 + ... + 1/30
I run the code unsuccessfully
import decimal
import math
var=decimal.Decimal(1/i)
for i in range(1,31):
print(sum(var))
I get the error
'Decimal' object is not iterable
How can you make the iterable function in Python?
...
Hello everybody,
I want to know how to find an element in list without iteration
...
I have a Python application. It has an SQLite database, full of data about things that happen, retrieved by a Web scraper from the Web. This data includes time-date groups, as Unix timestamps, in a column reserved for them. I want to retrieve the names of organisations that did things and count how often they did them, but to do this for...
Attempt to generalize my questions...
I want to execute a stored procedure for each result returned by a SELECT statement.
Mentally I want to try something like
EXEC myStoredProc (SELECT id FROM sometable WHERE cond = @param)
More details related to my specific case...
I have a SaaS application. I would like to delete a tenant from th...
My requirement is -using XSLT- to show a dropdown list with the US states and print 'selected' on one specific that is declared in the XML which will use my style sheet.
I was thinking on declare an array with the states and iterate it but I don't know how to do it.
NOTE: More ideas are welcome ;)
...
Possible Duplicate:
Elements order - for (... in ...) loop in javascript
Assume you have code like this:
var a = {}
a.a = 1;
a.c = 2;
a.b = 3;
for (var i in a) {
console.log(a[i]);
}
Are 1, 2, and 3 guaranteed to be printed in that order? I've tested and this has been the case so far, but I don't know if it'll always be ...
I want to define a class that supports __getitem__, but does not allow iteration.
for example:
class b:
def __getitem__(self, k):
return k
cb = b()
for x in cb:
print x
What could I add to the class b to force the "for x in cb:" to fail?
...
A reddit thread brought up an apparently interesting question:
Tail recursive functions can trivially be converted into iterative functions. Other ones, can be transformed by using an explicit stack. Can every recursion be transformed into iteration?
The (counter?)example in the post is the pair:
(define (num-ways x y)
(case ((= x 0...
I have created a multidimensional array in Python like this:
self.cells = np.empty((r,c),dtype=np.object)
Now I want to iterate through all elements of my twodimensional array, and I do not care about the order. How do I achieve this?
...
This question is quite simple but I have run into the problem a few times.
Let's say you do something like:
cars = Vehicle.find_by_num_wheels(4)
cars.each do |c|
puts "#{c.inspect}"
end
This works fine if cars is an array but fails if there is only one car in the database. Obviously I could do something like "if !cars.length.nil?...
Hi,
I have several problems planning an iteration for a single week. We use XP and TDD in Pairs and it is hard to decide who is pairing with whom. Is there any tool support for planning an iteration that also supports panning of pairs.
...
I'm looking for the standard idiom to iterate over an NSArray. My code needs to be suitable for OS X 10.4+.
...
In Java, is it faster to iterate through an array the old-fashioned way,
for (int i = 0; i < a.length; i++)
f(a[i]);
Or using the more concise form,
for (Foo foo : a)
f(foo);
For an ArrayList, is the answer the same?
Of course for the vast bulk of application code, the answer is it makes no discernible difference so the mo...
I've recently seen in a couple of different places comments along the lines of, "I learned about recursion in school, but have never used it or felt the need for it since then." (Recursion seems to be a popular example of "book learning" amongst a certain group of programmers.)
Well, it's true that in imperative languages such as Java a...
Hi i have question about iterate throught the Alphabet.
I would like to have a loop that begins with "a" and ends with "z". After that the loop begins "aa" and count to "az". after that begins with "ba" up to "bz" and so on...
Anybody know some solution?
Thanks
EDIT: I forgot that i give an char "a" to the function then the function m...
hi im preparing for an exam and i am new to c# i am having problem with a question that i have
what i am having problem is that i need to find out how many times the number greater than or less than one appears in the array for example
if i have an array {1,1,1,2,3,-18,45,1} here numbers that are greater than or less than one appears...
I have a generator that generates a series, for example:
def triangleNums():
'''generate series of triangle numbers'''
tn = 0
counter = 1
while(True):
tn = tn + counter
yield tn
counter = counter + 1
in python 2.6 I am able to make the following calls:
g = triangleNums() # get the generator
g.n...