Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

257
Views
Los índices de lista no deben ser de lista

Necesito tomar medidas cuando pole[i][j] == 1 , pero arroja un error:

TypeError: los índices de la lista deben ser números enteros o segmentos, no una lista

 pole = [[0,1,0], [1,0,1], [0,1,1]] for i in pole: for j in pole: if pole[i][j] == 1: my_code()
over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Utiliza for i in pole que obtiene los valores reales del pole no los índices. Aquí está el código corregido:

 pole = [[0,1,0], [1,0,1], [0,1,1]] for i in range(len(pole)): for j in range(len(pole[i])): if pole[i][j] == 1: my_code()

Alternativamente, podría usar los valores, no los índices, así:

 pole = [[0,1,0], [1,0,1], [0,1,1]] for i in pole: for j in i: if j == 1: my_code()
over 4 years ago · Santiago Trujillo Report

0

un bucle for-in itera sobre los elementos de una lista, no sobre sus índices. Además, tenga en cuenta que tiene el ciclo interno realizando la misma iteración que el ciclo externo, sin iterar sobre la sublista:

 for x in pole: for y in x: if y == 1: my_code()
over 4 years ago · Santiago Trujillo Report

0

Bueno, técnicamente hablando, dado que my_code() no usa i o j , podrías hacer algo como esto:

 for _ in range(sum(map(sum, pole))): my_code()

Los elementos en polo no necesariamente tienen que ser 0 y 1; podría desencadenar otras condiciones, por ejemplo:

 sum(map(lambda x: sum(y > 0 for y in x), pole)
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!