Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Error:unsupported operand type(s) for ** or pow(): 'list' and 'int'
#1
this code is generating the error message written on the subject line.
I am not understanding why.

L=[1,2]
L3=[3*L]
L4=[k**2 for k in L3]
print(L4)
Quote
#2
did you print L3 to see what it is? :-)
Quote
#3
yes,

[[1, 2, 1, 2, 1, 2]]

I am still unsure on why you asked me that.
Quote
#4
(Mar-22-2019, 12:54 PM)mcgrim Wrote: yes,

[[1, 2, 1, 2, 1, 2]]

I am still unsure on why you asked me that.
don't you see that L3 is list of lists (i.e. there is actually just one element)
So, it the list comprehension value of k is [1, 2, 1, 2, 1, 2]
and you cannot raise a list to power 2

L=[1,2]
L3=[3*L]
print(L3)
for k in L3:
    print(k)
    print(k ** 2)
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Error Message: TypeError: unhashable type: 'set' twinpiques 4 887 May-22-2019, 02:31 PM
Last Post: twinpiques
  Type Error Confusion Oliver 4 2,428 Dec-06-2017, 03:20 PM
Last Post: Oliver
  type error and access violation error pyopengl hsunteik 0 1,039 Nov-04-2017, 04:51 AM
Last Post: hsunteik
  AUCPR of individual features using Random Forest (Error: unhashable Type) melissa 1 1,076 Jul-10-2017, 12:48 PM
Last Post: sparkz_alot
  Why am I getting a type error? WagmoreBarkless 7 2,063 Jan-19-2017, 10:29 PM
Last Post: ichabod801

Forum Jump:


Users browsing this thread: 1 Guest(s)