Let's say I have an array [2, 3], and I want to pass that into a function. Not as function([2, 3]), as function(2, 3). Is there anyway to do that, like function(pass(array))?
866
In the following method definitions, what does the * and ** do for param2?  def foo(param1, *param2): def bar(param1, **param2):
16381
I would want to do something like:  &gt;&gt;&gt; lst = [1, 2, 3, 4, 5] &gt;&gt;&gt; lst.find(lambda x: x % 2 == 0) 2 &gt;&gt;&gt; lst.findall(lambda x: x % 2 == 0) [2, 4]   Is there anything nearing such behavior in Python's standard libraries?  I know it's very easy to roll-your-own here, but I'm looking for a more standard way.
10523
I know how to do it normally, but I could swear that you could fill out out like a[0] = {0,0,0,0}; How do you do it that way? I did try Google, but I didn't get anything helpful.
54124
What is the most efficient way to check if an array is a flat array of primitive values or if it is a multidimensional array? Is there any way to do this without actually looping through an array and running is_array() on each of its elements?
104870
I've been working on this task (see screenshot).     Here's my answer to it so far:  var sum_pairs=function(ints, s){   //your code here    var ptr_1 = 0,       ptr_2 = 0,       i = 0,       j = 0,       len = ints.length,       j_min = len,       arr_sum = [];    for (i; i &lt; len-1; i++){     for (j = i+1; j &lt; len; j++){       if(ints[i] + ints[j] === s){         if (j &lt; j_min){           j_min = j;           arr_sum = [parseInt(ints[i]), parseInt(ints[j])]         }       }     }   }  return ( (arr_sum.length === 0)? undefined : arr_sum );   }   However, while the tests all pass, it throws an STDERR about 'optimising the code':    How might I be able to optimise my code further?
2624
Is there any way I can separate a List&lt;SomeObject&gt; into several separate lists of SomeObject, using the item index as the delimiter of each split?  Let me exemplify:  I have a List&lt;SomeObject&gt; and I need a List&lt;List&lt;SomeObject&gt;&gt; or List&lt;SomeObject&gt;[], so that each of these resulting lists will contain a group of 3 items of the original list (sequentially).  eg.:   Original List: [a, g, e, w, p, s, q, f, x, y, i, m, c] Resulting lists: [a, g, e], [w, p, s], [q, f, x], [y, i, m], [c]   I'd also need the resulting lists size to be a parameter of this function.
5654
What is the difference between using  on the array element as opposed to using ?   For example:  myArray = ['a', 'b', 'c', 'd'];  delete myArray[1]; //  or myArray.splice (1, 1);   Why even have the splice method if I can delete array elements like I can with objects?
82341
example:  a_list = [1, 2, 3] a_list.len() # doesn't work len(a_list) # works   Python being (very) object oriented, I don't understand why the 'len' function isn't inherited by the object.  Plus I keep trying the wrong solution since it appears as the logical one to me
4188
While I was investigating a problem I had with lexical closures in Javascript code, I came along this problem in Python:  flist = []  for i in xrange(3):     def func(x): return x * i     flist.append(func)  for f in flist:     print f(2)   Note that this example mindfully avoids lambda. It prints "4 4 4", which is surprising. I'd expect "0 2 4".   This equivalent Perl code does it right:  my @flist = ();  foreach my $i (0 .. 2) {     push(@flist, sub {$i * $_[0]}); }  foreach my $f (@flist) {     print $f-&gt;(2), "\n"; }   "0 2 4" is printed.  Can you please explain the difference ?    Update:   The problem is not with i being global. This displays the same behavior:  flist = []  def outer():     for i in xrange(3):         def inner(x): return x * i         flist.append(inner)  outer() #~ print i   # commented because it causes an error  for f in flist:     print f(2)   As the commented line shows, i is unknown at that point. Still, it prints "4 4 4".
29305
What does it mean to extend a function? Can someone please give an example?  Thanks in advance!
119239
I have a variable, x, and I want to know whether it is pointing to a function or not.  I had hoped I could do something like:  &gt;&gt;&gt; isinstance(x, function)   But that gives me:  Traceback (most recent call last):   File "&lt;stdin&gt;", line 1, in ? NameError: name 'function' is not defined   The reason I picked that is because  &gt;&gt;&gt; type(x) &lt;type 'function'&gt;
20930
I would like to filter an array of items by using the map() function. Here is a code snippet:  var filteredItems = items.map(function(item) {     if( ...some condition... )     {         return item;     } });   The problem is that filtered out items still uses space in the array and I would like to completely wipe them out.  Any idea?  EDIT: Thanks, I forgot about filter(), what I wanted is actually a filter() then a map().  EDIT2: Thanks for pointing that map() and filter() are not implemented in all browsers, although my specific code was not intended to run in a browser.
1267
Python provides the "*" operator for unpacking a list of tuples and giving them to a function as arguments, like so:  args = [3, 6] range(*args)            # call with arguments unpacked from a list   This is equivalent to:  range(3, 6)   Does anyone know if there is a way to achieve this in PHP? Some googling for variations of "PHP Unpack" hasn't immediately turned up anything.. perhaps it's called something different in PHP?
2911
I have an array of Foo objects. How do I remove the second element of the array?  I need something similar to RemoveAt() but for a regular array.
1431
Foo* set = new Foo[100]; // ... delete [] set;   You don't pass the array's boundaries to delete[]. But where is that information stored? Is it standardised?
62479
I am doing , and am having a few problems with function notation. I understand the form f(x).  What does the form f: x ↦ y mean? Could you also give one or two examples?  And, if possible, state your source. Thank you.
24071
I'm trying to understand Python's approach to variable scope. In this example, why is f() able to alter the value of x, as perceived within main(), but not the value of n?  def f(n, x):     n = 2     x.append(4)     print('In f():', n, x)  def main():     n = 1     x = [0,1,2,3]     print('Before:', n, x)     f(n, x)     print('After: ', n, x)  main()   Output:  Before: 1 [0, 1, 2, 3] In f(): 2 [0, 1, 2, 3, 4] After:  1 [0, 1, 2, 3, 4]