Quantcast

set and list in Notebook

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

set and list in Notebook

caoimhinp
Error found with list() in Notebook.  Also confirmed that the same occurs from the ipython command line but not from the python 2.7 command line.

See output below:

In [26]:

dup_list = [1, 1, 3, 7, 3, 5, 8, 2, 4, 5]
print dup_list
now_a_set = set(dup_list)
print now_a_set
now_list = list(now_a_set) #this should work and doesn't
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
C:\Users\caoimhin\<ipython-input-26-033034ce7270> in <module>()
      3 now_a_set = set(dup_list)
      4 print now_a_set
----> 5 now_list = list(now_a_set) #this should work and doesn't

TypeError: 'list' object is not callable

[1, 1, 3, 7, 3, 5, 8, 2, 4, 5]
set([1, 2, 3, 4, 5, 7, 8])
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: set and list in Notebook

Jon Olav Vik-3
caoimhinp <kevin.gp <at> gmail.com> writes:

> dup_list = [1, 1, 3, 7, 3, 5, 8, 2, 4, 5]
> print dup_list
> now_a_set = set(dup_list)
> print now_a_set
> now_list = list(now_a_set) #this should work and doesn't
> TypeError: 'list' object is not callable

This works fine on my system (IPython 0.13beta, Python 2.7). Are you sure you
haven't overwritten the name "list"? What does "print list" give you?


_______________________________________________
IPython-User mailing list
[hidden email]
http://mail.scipy.org/mailman/listinfo/ipython-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: set and list in Notebook

caoimhinp
That's possible but what I've posted is all that is in my Notebook -- but not all that _was_ in the Notebook.

I re-checked from the ipython command line and it does work correctly.
Killing the tab and starting a new Notebook (flushing all variables) made it function correctly.
I can only assume that there was a typo in previous cells that were deleted.

Thanks.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: set and list in Notebook

Thomas Kluyver-2
On 19 June 2012 18:19, caoimhinp <[hidden email]> wrote:
> That's possible but what I've posted is all that is in my Notebook -- but not
> all that _was_ in the Notebook.

A cell you've run stays run, even if you delete it. The "In [26]:" in
your example means its the 26th bit of code you ran - and any of the
25 before it could have overwritten list.

Best wishes,
Thomas
_______________________________________________
IPython-User mailing list
[hidden email]
http://mail.scipy.org/mailman/listinfo/ipython-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: set and list in Notebook

caoimhinp
 
Thomas Kluyver-2 wrote
A cell you've run stays run, even if you delete it. The "In [26]:" in
your example means its the 26th bit of code you ran - and any of the
25 before it could have overwritten list.
Another thing to note is that all previously defined variables are persistent until the kernel is restarted. This may seem obvious but my initial tendency was to look at different cells as new instances.
Loading...