# Lists in Python doubt in relate

hello guys, my question is how to relate these two lists, for example: if the DISTANCE of force 1 is 3 and this is in index 4 of the first list, the FORCE of force 1 should be found in index 4 of the second list.

What I have tried :

``````from math import *

a=0
l=int(input(' beam length = ') )
x=int(input(' leading end value = ') )
y=int(input(' endpoint value = ') )
f1=int(input(' force 1 = '))
x1=int(input(' distance 1 = '))
f2=int(input(' force 2 = '))
x2=int(input(' distance 2 = '))
p=int(input(' points = ') )

distĂ˘ncia = [ ]
distĂ˘ncia.append(0)
for n in range(0,p):
a +=(l/p)
distĂ˘ncia.append(a)

print(' distance = ',distĂ˘ncia)

lst = [0] * p
lst[0]=x
lst[-1]=y
print(' forces acting on points = ',lst)
``````

Not sure if I understand.
Your question is: how to find element from one list in another list?

basically, for example if force 1 = 5 and distance 1 = 3 â€¦ if in the first list 3 is index 4 , in the second 5 must be placed in index 4 of the other list

You can use index method I guess. I wrote some generic example for you. I hope you can get some logic from it for your code.

``````a = 3
b = 5
list1 = [0, 0, 0, 0, a]
index = list1.index(a)
print(index)###4
list2 = [0, 0, 0, 0, 0, 0]
list2[index] = b
print(list2)###[0, 0, 0, 0, 5, 0]
``````
2 Likes

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.