Performing mathematical operations on value in lists

I am trying to add a value in a list to an outside integer. The list is from a .text file "apiresp":

\`APIlines = [] # Declare an empty list named APIlines.

with open ('apiresp.txt', 'rt') as myfile: # Open airesp.txt for reading text data.

for APIline in myfile: # For each line, stored as myfile,

APIlines.append(APIline) # add its contents to APIlines.

hpa = (APIlines[5])

s = [float(s) for s in re.findall(r'-?\d+.?\d*', hpa)] # function to extract numbers from string

res = [float(ele) for ele in s]

b = []

for item in s: b.append(float(item)) # convert the string to a float which we can use in mathematical operations

res1 = res + 1

print(res1)\\

I was under the impression that line 10 would 'extract' the object from the list into a float and thus we can use for mathematical operations, but I'm very new to this so I'm sorry if it's a stupid question/assumption.

It's returning the following error:

\\line 36, in

res1 = res + 1

TypeError: can only concatenate list (not "int") to list\\

This is for a late school project so any help would be appreciated. Thanks guys :)



from Recent Questions - Stack Overflow https://ift.tt/3dugT1N
https://ift.tt/eA8V8J

Comments

Popular posts from this blog

Today Walkin 14th-Sept

Hibernate Search - Elasticsearch with JSON manipulation

Spring Elasticsearch Operations