Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

325
Vistas
How to find the indices of items in a list, which are present in another list?

I want to essentially use one list ie.

L = [10, 10, 100, 10, 17, 15]

and using another list

R = [10, 15] 

want to return

N = [0, 1, 3, 5] // indices of L that return the values in R

I tried using L.index() to get the indices but that only returns the first value. I then tried running a for loop over L and using L.index(R[0]) every time, but similarly that only returns the first indices it finds at.

 for i in range(len(L)):
       j = R[i]
       N.append(L.index(j))
 return N

This would return index out of range which makes sense, but how do I get it to run through the L?

over 4 years ago · Santiago Trujillo
3 Respuestas
Responde la pregunta

0

N = []

for i in range(len(L)):

    if L[i] in R:
        N.append(i)

or with a generator

N = [i for i in range(len(L)) if L[i] in R]

or with arrays

import numpy as np

N=np.where(np.isin(L,R))
over 4 years ago · Santiago Trujillo Denunciar

0

N = []  
for i, num in enumerate(L):  
    if num in R:  
        N.append(i)  
over 4 years ago · Santiago Trujillo Denunciar

0

[i for i,l in enumerate(L) if l in R]
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda