• Register

Jupyter mi ne pretovri terk v seznam

+6 votes
116 views

 l = ['my', 'name', 'is', 'mr', 'list']
print(l)
tuple(l)
print(tuple)

Koda je skopirana iz stackoverflowa. Jupyter mi vrne:

['my', 'name', 'is', 'mr', 'list']
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-66-7df1177613da> in <module>()
      1 l = ['my', 'name', 'is', 'mr', 'list']
      2 print(l)
----> 3 tuple(l)
      4 print(tuple)

TypeError: 'tuple' object is not callable


Kaj delam narobe?
asked Oct 12, 2016 by zhanglava (1,050 points)
Glede errorja: verjetno ste povozili objekt tuple. Naredite restarts kernela in izvedite samo zgornje vrstice.

1 Answer

+4 votes
 
Best answer
Takole dela:

m = ['my', 'name', 'is', 'mr', 'list']
print(m)
n = tuple(m)

print(20 * '-')
print(n)

če narediš takole:

 l = ['my', 'name', 'is', 'mr', 'list']
print(l)
print(tuple(l))

boš printal terko. Ampak l bo še vedno seznam, ker tuple(l) ti prikaže l kot terko (spremeni) a ne shrani! Moraš shraniti kot novo vrednost ali pa :

 

 l = ['my', 'name', 'is', 'mr', 'list']
print(l)

l = tuple(l)

print(20 * '-')
print(l)
answered Oct 12, 2016 by tilen.mlinaric (7,770 points)
selected Oct 12, 2016 by janko.slavic
...