My code is:  a = {"a1","a2","a3"} b = a b[1] = "b1" print(a[1])   I can't understand why the result is "b1" instead of "a1".  The same is:   a = {"a1","a2","a3"} b = a c = b b[1] = "b1" c[2] = "c2" print(a[1]) print(a[2]) print(a[3])   The result will be:  "b1"  "c2" "a3".  Can I copy variables in another way?
123912
Recently I wrote a bit of Lua code something like:  local a = {} for i = 1, n do    local copy = a    -- alter the values in the copy end   Obviously, that wasn't what I wanted to do since variables hold references to an anonymous table not the values of the table themselves in Lua.  This is clearly laid out in , but I'd forgotten about it.  So the question is what should I write instead of copy = a to get a copy of the values in a?
23996
I am a newbie to Python and have come across the following example in my book that is not explained very well. Here is my print out from the interpreter:  &gt;&gt;&gt; s = 'spam' &gt;&gt;&gt; s[:-1] 'spa'   Why does slicing with no beginning bound and a '-1' return every element except the last one? Is calling s[0:-1] logically the same as calling s[:-1]? They both return the same result. But I'm not sure what python is doing exactly. Any help would be greatly appreciated.
55320
In the following question  the notation $c\in ]a,b[$ is used. What does this mean? I have never seen it before.
2664
In python, is there a difference between calling clear() and assigning {} to a dictionary? If yes, what is it? Example:d = {"stuff":"things"} d.clear()   #this way d = {}      #vs this way
106335
What does the following mean?  Class.Function(variable := 1 + 1)   What is this operator called, and what does it do?
60559
Is there is any difference between these two.  [[ $a == z* ]]   and   [ $a == z* ]    Can I have an example where they would have different outputs?  Furthermore, how does the working of [[ ]] differs from [ ]?
872
In Java, arrays don't override toString(), so if you try to print one directly, you get the className + '@' + the hex of the  of the array, as defined by Object.toString():  int[] intArray = new int[] {1, 2, 3, 4, 5}; System.out.println(intArray);     // prints something like '[I@3343c8b3'   But usually, we'd actually want something more like [1, 2, 3, 4, 5]. What's the simplest way of doing that? Here are some example inputs and outputs:  // Array of primitives: int[] intArray = new int[] {1, 2, 3, 4, 5}; //output: [1, 2, 3, 4, 5]  // Array of object references: String[] strArray = new String[] {"John", "Mary", "Bob"}; //output: [John, Mary, Bob]
29934
I'm sure there's a nice way to do this in Python, but I'm pretty new to the language, so forgive me if this is an easy one!  I have a list, and I'd like to pick out certain values from that list. The values I want to pick out are the ones whose indexes in the list are specified in another list.  For example:  indexes = [2, 4, 5] main_list = [0, 1, 9, 3, 2, 6, 1, 9, 8]   the output would be:  [9, 2, 6]   (i.e., the elements with indexes 2, 4 and 5 from main_list).  I have a feeling this should be doable using something like list comprehensions, but I can't figure it out (in particular, I can't figure out how to access the index of an item when using a list comprehension).
100626
For example {a..c}{1..3} expands to a1 a2 a3 b1 b2 b3 c1 c2 c3.   If I wanted to print a1 b1 c1 a2 b2 c2 a3 b3 c3, is there an analogous way to do that? What's the simplest way?
4791
Say i have this PHP code:  $FooBar = "a string";   i then need a function like this:  print_var_name($FooBar);   which prints:  FooBar   Any Ideas how to achieve this? Is this even possible in PHP?
29869
In php, I often need to map a variable using an array ... but I can not seem to be able to do this in a one liner. c.f. example:  // the following results in an error: echo array('a','b','c')[$key];  // this works, using an unnecessary variable: $variable = array('a','b','c'); echo $variable[$key];   This is a minor problem, but it keeps bugging every once in a while ... I don't like the fact, that I use a variable for nothing ;)
35871
How does Python evaluate the expression 1+++2?  How many ever + I put in between, it is printing 3 as the answer. Please can anyone explain this behavior  And for 1--2 it is printing 3 and for 1---2 it is printing -1
45206
What is the difference between Object Literals and Array Literals in JavaScript? I know it has something to do with the length method but i don't fully understand it.
109226
Given an array:  array1 = [1 2 3];   I have to reverse it like so:  array1MirrorImage = [3 2 1];   So far I obtained this ugly solution:  array1MirrorImage = padarray(array1, [0 length(array1)], 'symmetric', 'pre'); array1MirrorImage = array1MirrorImage(1:length(array1));   Is there a prettier solution to this?
81621
If I write the following class:  public class Example {        int j;       int k;        public Example(int j, int k) {            j = j;            k = k;       }        public static void main(String[] args) {            Example exm = new Example(1,2);            System.out.println(exm.j);            System.out.println(exm.k);       }  }   The program compiles, but when I run the program, the main method will print out two 0s. I know that in order to say that I want to initialize the instance variables in the constructor I have to write:  this.j = j; this.k = k;   But if I don't write it, then which variable is evaluated (or considered) in the constructor (on the left and on the write hand side of the expressions)? Is is the argument or the instance variable? Does it make a difference?  Are there other cases where the use of this is obligatory?
28825
These seem to be very similar as they both separate two operands. When would one be used over the other? Is there any difference in the math spacing surrounding them?  How would the spacing in these relate to to the spacing produced by \mathop?
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)