TypeError: list object is not callable [duplicate]

2024/11/17 15:47:02

I can't find the problem i'm facing...
this is exactly what the error tells me:

File "C:/Users/Rodrigo Villalta/Desktop/listasparimpar.py", line 38,
in listas_par_imparif lista2(m) > lista2 [m+1]: TypeError: 'list' object is not callable

This is the code:

def listas_par_impar(lista,lista2):
lista3=[]
lista4=[]
for i in lista2:if i % 2 == 0:lista=lista+[i]else:passfor i in lista:if i %2 != 0:lista2=lista2+[i]else:passfor i in lista:if i%2==0:if i not in lista3:lista3=lista3+[i]lista=lista[1:]for i in lista2:if i%2!=0:if i not in lista4:lista4=lista4+[i]lista=lista[1:]for recorrido in range(1,len(lista)):for posicion in range(len(lista)-recorrido):if lista(posicion) > lista [posicion+1]:lista[posicion], lista[posicion+1] = lista[posicion+1], lista[posicion]for r in range(1,len(lista2)):for m in range(len(lista2)-r):if lista2(m) > lista2 [m+1]:lista2[m], lista2[m+1] = lista2[m+1], lista2[m]print (lista4, lista3)
Answer

In this line:

if lista2(m) > lista2 [m+1]:

… you've written lista2(m) instead of lista2[m].

This means you're trying to call lista2 like a function, with argument m. What you wanted to do is index lista2 like a list, with index m.

https://en.xdnf.cn/q/118787.html

Related Q&A

Tokenise text and create more rows for each row in dataframe

I want to do this with python and pandas.Lets suppose that I have the following:file_id text 1 I am the first document. I am a nice document. 2 I am the second document. I am an even …

Is the example of the descriptor protocol in the Python 3.6 documentation incorrect?

I am new to Python and looking through its documentation I encountered the following example of the descriptor protocol that in my opinion is incorrect. .It looks like class IntField:def __get__(self, …

How to clean a string to get value_counts for words of interest by date?

I have the following data generated from a groupby(Datetime) and value_counts()Datetime 0 01/01/2020 Paul 803 2 01/02/2020 Paul 210982360967 1 …

Folium - Map doesnt appear

I try to get map through Folium but only thing I can see is marker on blank page. Id like to know where is problem lies, in explorer or coding. map.py import foliummap = folium.Map(location = [46.20, 6…

python tkinter exe built with cx_Freeze for windows wont show GUI

PROBLEM SOLVED. the issue was with jaraco module, that i used for clipboard manipulation, i used pyperclip instead.I made a python app with tkinter that works fine, but I wanted to make an exe from it …

lxml tree connection and properties

I have a .dtsx file so, I have multiple components with connections, so I need to extract component that have especific connection, but I can not handle that, example: <components><component r…

Python recursive function call with if statement

I have a question regarding function-calls using if-statements and recursion. I am a bit confused because python seems to jump into the if statements block even if my function returns "False"…

How can I list all 1st row values in an Excel spreadsheet using OpenPyXL?

Using the OpenPyXL module with Python 3.5, I was able to figure out how many columns there are in a spreadsheet with:In [1]: sheet.max_column Out [1]: 4Then I was able to list the values in each of the…

Using matplotlib on non-0 MPI rank causes QXcbConnection: Could not connect to display

I have written a program that uses mpi4py to do some job (making an array) in the node of rank 0 in the following code. Then it makes another array in the node of rank 1. Then I plot both the arrays. T…

ioerror errno 13 permission denied: C:\\pagefile.sys

Below is my code, what I am trying to achieve is walking through the OS generating a MD5 hash of every file the code is functional, however, I receive the error in the title "ioerror errno 13 perm…