Running python 2.7 in linux
Below are two extremes. Can I get some guidance on this?
Thanks,
-Denis H
>>> a=zeros((2,3),dtype=int)
>>> b=a
>>> a[:,0]=[1,2]
>>> a
array([[1, 0, 0],
[2, 0, 0]])
>>> b
array([[1, 0, 0],
[2, 0, 0]])
>>> a=2
>>> a
2
>>> b
array([[1, 0, 0],
[2, 0,
Thanks for the responses.
The distinction between replacement and modification seems to capture the
essential aspect and helps to clarify the issue for me.
spir:
Quite the opposite, in python "symbolic assignment" (where the right side
also is a symbol) never copies, in fact never creates a new v
On Tue, Jan 28, 2014 at 12:28 AM, spir wrote:
>
>
> a = [1, [1,2]]
b = a
b
>>> [1, [1, 2]]
>
>> b is a
>>> True
>
> a's and b's values are a single, unique object... as long as I only
> modified them (the values) partly:
>
> a = [1,[2,3]]
a[0] = 0
b
>>> [0, [
On Tue, Jan 28, 2014 at 5:19 PM, Alan Gauld wrote:
> On 28/01/14 19:00, Denis Heidtmann wrote:
>
>> On Tue, Jan 28, 2014 at 12:28 AM, spir >
>
> This is getting confusing with two times Denis!
>
> <mailto:denis.s...@gmail.com>> wrote:
>>
>>
Running python 2.7 on Ubuntu 12.04
Code:
def fib2(n):
if n==1:
return 1
elif n==2:
return 1
else:
return fib2(n-2) +fib2(n-1)
The above works:
>>> fib2(7)
13
>>> fib2(4)
3
>>> for i in range(4):
... print fib2(i)
...
The above results in an error:
Traceback (most recent call last):
File
On Fri, Feb 7, 2014 at 9:05 PM, rakesh sharma
wrote:
> Hi
>
> Shouldn't your code be like this
>
> def fib(n):
> if n==0:
> return 0
> else:
> return n + fib(n-1)
>
> this works
>
for i in range(4):
> print fib(i)
>
> 0
> 1
> 3
> 6
interesting, but the Fibonacci sequence is 1,1,2,3,5,8,
In a coursera python course video the following code was presented:
a = [4,5,6]
def mutate_part(x):
a[1] = x
mutate_part(200)
The presenter said something like "a is a global variable, so a becomes
[4,200,6] after running mutate_part(200)."
Indeed it does, but why does this work without s
On Sun, May 4, 2014 at 6:44 PM, Dave Angel wrote:
> C Smith Wrote in message:
>> Sorry.
>>
>> I meant for example:
>> list1 = [1,2,3]
>> list2 = [3,4,5]
>>
>> newList = list1 + list2
>>
>> versus
>>
>> for x in list2:
>> list1.append(x)
>>
>> Which is the preferred way to add elements from on
On Tue, May 6, 2014 at 1:21 PM, Dave Angel wrote:
> You're right to be confused; my fingers were confused typing my
> last sentence. It should have ended:
>... you should use + .
>
> Likewise the previous thought should have said:
>
> But in any similar
> example, if list2 is t