Hi could someone help with this code,i am getting the error: " 'int' object is not iterable " at line 28(A.extend(n)) since i am new to python i am unable to figure out a solution any help is appreciated   Edit:I tried append earlier and got a memory error earlier and was wondering if extend() was the correct way to add elements but it seems like I made a mistake and the ended up with a infinite loop  Thanks for the advice it really helped me   print("Ax^2+Bx+C") a = int(input("a")) b = int(input("b")) c = int(input("c")) i, j, k, l = 0, 0, 0, 0 A = [] C = [] B = [] ano = []   bno = []   no = 0 noc = 0   n = 2 a2 = a c2 = c  if (a != 1) or (b != 1): while i != 1:     while a2 % n == 0 and c2 % n == 0:         if a2 % n == 0:             a2 /= n             # A.extend(n)             no += 1         if c2 % n == 0:             c2 /= n             # A.extend(n)             no += 1     A.extend(n)     ano.extend(no)     no = 0     n += 1     if a2 == 1:         A.extend(1)         A.extend(1)           i = 1
2267
What's the difference between the list methods append() and extend()?
13767
What is the correct way of iterating over a vector in C++?  Consider these two code fragments, this one works fine:  for (unsigned i=0; i &lt; polygon.size(); i++) {     sum += polygon[i]; }   and this one:  for (int i=0; i &lt; polygon.size(); i++) {     sum += polygon[i]; }   which generates warning: comparison between signed and unsigned integer expressions.  I'm new in the world of C++, so the unsigned variable looks a bit frightening to me and I know unsigned variables can be dangerous if not used correctly, so - is this correct?
34320
I've used recursion quite a lot on my many years of programming to solve simple problems, but I'm fully aware that sometimes you need iteration due to memory/speed problems.  So, sometime in the very far past I went to try and find if there existed any "pattern" or text-book way of transforming a common recursion approach to iteration and found nothing. Or at least nothing that I can remember it would help.   Are there general rules? Is there a "pattern"?
34074
Why this code isn't working? In my mind the next() method should move the cursor for the next item of the list...  List&lt;string&gt; listX = new List&lt;String&gt; {'A','B','C'}; while(listX.iterator().hasNext())     system.debug(listX.iterator().next());   When I try to run it I receive a error message of exceed a governor limit of CPU time. It's happend because the next() method doesn't move the cursor for the next list item. Every time returns "A".
9114
Suppose we have an iterator (an infinite one) that returns lists (or finite iterators), for example one returned by infinite = itertools.cycle([[1,2,3]])  What is a good Python idiom to get an iterator (obviously infinite) that will return each of the elements from the first iterator, then each from the second one, etc. In the example above it would return 1,2,3,1,2,3,.... The iterator is infinite, so itertools.chain(*infinite) will not work. Related
49176
Why does python 2.5.2 have the following behavior  &gt;&gt;&gt;[2].extend([]) == [2] False  &gt;&gt;&gt; [2].extend([]) == None True  $ python --version Python 2.5.2   I assume I'm not understanding something here, but intuitively I'd think that [2].extend([]) should yield [2]
98138
In Python, I can do:  &gt;&gt;&gt; list = ['a', 'b', 'c'] &gt;&gt;&gt; ', '.join(list) 'a, b, c'   Is there any easy way to do the same when I have a list of objects?  &gt;&gt;&gt; class Obj: ...     def __str__(self): ...         return 'name' ... &gt;&gt;&gt; list = [Obj(), Obj(), Obj()] &gt;&gt;&gt; ', '.join(list) Traceback (most recent call last):   File "&lt;stdin&gt;", line 1, in &lt;module&gt; TypeError: sequence item 0: expected string, instance found   Or do I have to resort to a for loop?
410
I needed to create a list of lists in Python, so I typed the following: my_list = [[1] * 4] * 3  The list looked like this: [[1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1]]    Then I changed one of the innermost values: my_list[0][0] = 5  Now my list looks like this: [[5, 1, 1, 1], [5, 1, 1, 1], [5, 1, 1, 1]]    which is not what I wanted or expected. Can someone please explain what's going on, and how to get around it?
98262
Why won't this work?  I'm trying to make an instance of a class delete itself.  &gt;&gt;&gt; class A():     def kill(self):         del self   &gt;&gt;&gt; a = A() &gt;&gt;&gt; a.kill() &gt;&gt;&gt; a &lt;__main__.A instance at 0x01F23170&gt;
109666
What is the best way to copy a list? I know the following ways, which one is better? Or is there another way?  lst = ['one', 2, 3]  lst1 = list(lst)  lst2 = lst[:]  import copy lst3 = copy.copy(lst)
6670
I was wondering how to check whether a variable is a class (not an instance!) or not.  I've tried to use the function isinstance(object, class_or_type_or_tuple) to do this, but I don't know what type would a class will have.  For example, in the following code  class Foo: pass   isinstance(Foo, **???**) # i want to make this return True.   I tried to substitute  "class" with ???, but I realized that class is a keyword in python.
57011
One of my Fellows asked me whether total induction is applicable to real numbers, too ( or at least all real numbers ≥ 0) . We only used that for natural numbers so far.  Of course you have to change some things in the inductive step, when you want to use it on real numbers.  I guess that using induction on real numbers isn't really possible, since $[r,r+\epsilon]$ with $\epsilon > 0$, $r \in \mathbb R$ is never empty.  Can you either give a good reason, why it isn't possible or provide an example where it is used?
76800
Do Apex collection classes implement Iterable interface? I want to write a generic function that can take any of the collection classes that support foreach. Is this possible?
119736
I have a try...except block in my code and When an exception is throw. I really just want to continue with the code because in that case, everything is still able to run just fine. The problem is if you leave the except: block empty or with a #do nothing, it gives you a syntax error. I can't use continue because its not in a loop. Is there a keyword i can use that tells the code to just keep going?
54890
I'm trying to used the Python syntax in ArcGIS 10's field calculator and am thoroughly confused. So far the most basic calculations are failing me, and I don't understand why. I'm trying to create a function to just set the values of all cells in a column to be a multiple of the argument that I pass in ( I wanted to try something simple to test it out, as anything more complicated I tried also failed).   However, the error messages are telling me that my syntax is incorrect:    but I can't understand what is incorrect.     As an aside, I'm also horrified at how hard it is to write readable python in the field calculator box as there is no syntax highlighting, or clear indentation. It would be quicker, and easier to write an external Python script to do this calculation, but I want to try to figure out how this new function worked within the program.
57572
I normally use the following idiom to check if a String can be converted to an integer.  public boolean isInteger( String input ) {     try {         Integer.parseInt( input );         return true;     }     catch( Exception e ) {         return false;     } }   Is it just me, or does this seem a bit hackish?  What's a better way?    See my answer (with benchmarks, based on the  by ) to see why I've reversed my position and accepted  to this problem.  I think this original code will be used by most people because it's quicker to implement, and more maintainable, but it's orders of magnitude slower when non-integer data is provided.
9898
Code like this often happens: l = [] while foo:     # baz     l.append(bar)     # qux  This is really slow if you're about to append thousands of elements to your list, as the list will have to be constantly resized to fit the new elements. In Java, you can create an ArrayList with an initial capacity. If you have some idea how big your list will be, this will be a lot more efficient. I understand that code like this can often be refactored into a list comprehension. If the for/while loop is very complicated, though, this is unfeasible. Is there an equivalent for us Python programmers?