logo
Tags down

shadow

TypeError:unsupported operand type[s] for -: 'list' and 'int'


By : angryGreen
Date : October 16 2020, 06:10 AM
wish helps you input().split() gives you a list, and you are trying to subtract it with an int, hence the error TypeError: unsupported operand type(s) for -: 'list' and 'int'
To fix it, you want to get the first element of the list after splitting the string via split, and convert that string to an integer via int(var)
code :
#Get the first element of the list after splitting the string, and convert that string to an integer
a=int(input().split('_F')[0])
b=int(input().split('_C')[0])

#Do the conversion
a1=(5/9*(a-32))
a2=(9/5*b+32)

#Print the temperatures
print(a1)
print(a2)
35.0
163.4


Share : facebook icon twitter icon

TypeError: unsupported operand type(s) for -: 'int' and 'list'


By : Linh Nguyen
Date : March 29 2020, 07:55 AM
wish of those help What's happening in answer to your direct question has been answered by @mellamokb and comments...
However, I would point out that Python already this builtin and would make it easier:
code :
from datetime import datetime
d = datetime.strptime('1312981', '%d%m%Y')
# datetime(1981, 12, 13, 0, 0)

TypeError: unsupported operand type(s) for -: 'list' and 'int'


By : Rick vDorp
Date : March 29 2020, 07:55 AM
seems to work fine The point of the problem is that you can't pass a list to your function. Your function wants an integer value.
code :
>>> fib(5)
13

TypeError For Unsupported Operand type 'int' and 'list'


By : theoracle
Date : March 29 2020, 07:55 AM
I wish this help you Your lowPrimes variable is a list of lists, so when you say for prime in lowPrimes, prime is a list, so you can't modulus an int by a list. Try changing lowPrimes = [[...]] to lowPrimes = [...] (remove one layer of brackets).
The error message is pretty instructive here. It's saying that you are trying to apply the % operator to an int and a list. Since you also have the line number you can see the expression it's referring to and that prime must have been a list.

TypeError: unsupported operand type(s) for ** or pow(): 'int' and 'list'


By : Derewigespiesser
Date : March 29 2020, 07:55 AM
it fixes the issue Can someone help me fix this TypeError? I am trying to raise 5 by a number n and print its last 2 digits , I believe this is what you are trying to do:
code :
#!/usr/bin/env python3.6
from sys import stdin, stdout


numbers = [int(x) for x in stdin.readline().rstrip().split()]
res = [5**x for x in numbers]
stdout.write(str(res[1] + res[0]))

TypeError: unsupported operand type(s) for ** or pow(): 'list' and 'int'


By : 김민수
Date : March 29 2020, 07:55 AM
wish helps you The variable astlist is a list. You're adding list1 to it several times which is also a list. But you're also adding a list to list1 each time: list1.append([x,y,z]). So ultimately astlist is a list containing multiple lists which each contain a list with three integers.
So when you write x,y,z=astlist[row] the variables x, y and z are actually lists, not integers. This means you're trying to compute x**2 but x is a list, not a number. This is why Python is giving you an error message as ** doesn't support raising a list to a power.
Related Posts Related Posts :
  • Python hex string encoding
  • Get week start date from week number
  • How to use imports from requirements.txt in python
  • Removing tab indent in ipython shell
  • I need to remove duplicates from a list but add the numeric value in them
  • Delay default arguments being read until function is called
  • Interpolate / fillna with a decay formula in pandas
  • What python package can translate Greek letter to ASCII requivalent?
  • How to get output of OS command from Jupyter notebook?
  • Printing AND writing the RIGHTLY formatted number
  • How do I create a shortcut to import most used python modules?
  • Matplotlib: Show selected date labels on x axis
  • Understanding memoization in Python
  • why does the len function return 2 on some iterations when they are all the same length?
  • Change in preference value does not affect the results of Affinity propagation Clustering
  • returning values inside a function
  • Why cant I use a variable in str slicing?
  • Section divider in Spyder
  • Conditional statement in selenium if element does not exists
  • Pandas : how to select index/row label in dataframe that matches a condition
  • What does zero do in A[0] in this code? Why not empty or another number?
  • Google App Engine urlfetch PayloadTooLargeError: Request exceeds 10 MiB limit for URL
  • Is there a way to set up optional arguments to bypass input arguments?
  • Suppress OpenMP debug messages when running Tensorflow on CPU
  • How to do GridSearchCV for F1-score in classification problem with scikit-learn?
  • Why does .pop() eventually stop and not keep removing items from a list until the list is empty?
  • How do I acess my Spider data from my main.py script?
  • Python Pandas Expand a Column of List of Lists to Two New Column
  • Overhead of python multiprocessing initialization is worse than benefits
  • Python Joining List and adding and removing characters
  • Adding an lxml library to project
  • Concatenating tensors in Tensorflow with None axis
  • Need help understanding why i get attribute error
  • How to force a MIDI device to report control status?
  • What does *** mean in Python -3?
  • How to get GFCC instead of MFCC in python?
  • How do I print a number n times in python?
  • How do i split a string wherever there are digits?
  • List Comprehension Python Prime numbers
  • "list index out of range" when reading data from file
  • What's the correct datetime format for the specified date string?
  • I cannot import CSV file?
  • Matplotlib pyplot plots look different after calling pandas profiling. How can I fix this?
  • Stopping all the instances of a specific region
  • Deal with Birtish summer time
  • Unable to use ColorWheel without loading kv (AttributeError)
  • What are these characters called: 。. !?etc Trying to split sentences stops working with non standard characters
  • rand.randint returning same number over and over?
  • Find longest sequence that does not contain a certain number
  • How do I convert a map object to list and also assign to a variable
  • sympy error: 'Symbol' object has no attribute 'pi'
  • How to remove words without vowels from a list in python
  • Downloading python to macbook
  • TypeError: __init__() missing 1 required positional argument: 'units'
  • Check if a class is a dataclass in Python
  • Unable to scrape google news heading via their class
  • Array of structs with dynamic allocation runs very slow in C in comparison to Python
  • Python Pandas - find all unique combinations of rows of a DataFrame without repeating values in the columns
  • How do I change the numbers in a cell to the word 'Bus' in Pandas Python
  • 'ascii' codec can't encode character : ordinal not in range (128)
  • shadow
    Privacy Policy - Terms - Contact Us © 35dp-dentalpractice.co.uk