Python Forum
Error:unsupported operand type(s) for ** or pow(): 'list' and 'int'
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)
Reply
#2
did you print L3 to see what it is? :-)
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
yes,

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

I am still unsure on why you asked me that.
Reply
#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)
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [pandas] TypeError: list indices must be integers or slices, not str but type is int. cspower 4 760 Dec-30-2023, 09:38 AM
Last Post: Gribouillis
  GroupBy - Sum = Error [datetime64 type does not support sum operations] BSDevo 4 2,542 Oct-27-2023, 07:22 PM
Last Post: BSDevo
  Numpy returns "TypeError: unsupported operand type(s) for *: 'numpy.ufunc' and 'int'" kalle 2 2,528 Jul-19-2022, 06:31 AM
Last Post: paul18fr
  Type error in Cross_val_score Vicral 0 1,806 Jul-20-2021, 12:18 PM
Last Post: Vicral
  type error array BrianPA 2 2,349 Jan-17-2021, 01:48 PM
Last Post: BrianPA
  Error binding parameter 0 - probably unsupported type. illmattic 7 10,225 Jul-18-2020, 09:32 PM
Last Post: illmattic
  Error Message: TypeError: unhashable type: 'set' twinpiques 4 18,753 May-22-2019, 02:31 PM
Last Post: twinpiques
  Type Error Confusion Oliver 4 14,379 Dec-06-2017, 03:20 PM
Last Post: Oliver
  type error and access violation error pyopengl hsunteik 0 3,298 Nov-04-2017, 04:51 AM
Last Post: hsunteik
  AUCPR of individual features using Random Forest (Error: unhashable Type) melissa 1 3,280 Jul-10-2017, 12:48 PM
Last Post: sparkz_alot

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020