Python Ma - Sajha Mobile
SAJHA MOBILE
Python Ma
Posts 2 · Viewed 4513 · Go to Last Post
comingsoon
· Snapshot 0
Like · Likedby · 0
 Hello,
            how to find the list element that whether it is on other lists or not?
I know  by the  loop method (found= True). If you know better way please let me know. Thanks.
L1 = [1,2,3,4,5]
L2=[2,3,6]
L3=[1,6,8] 
L4 = [3,10]

result: 
1: L1,L3
2:  L1,L2
3: L1,L2,L4
6: L2,L3



nepalinanu2013
· Snapshot 78
Like · Liked by · 0
not sure if this is the best way to do it:

load the elements to python disctionary ( that would be O(n) operation)
for each element in array, check if it exists in the disctionary , that would be another O(n) operation because hash lookup is O(1)
Please log in to reply to this post

You can also log in using your Facebook
View in Desktop
What people are reading
You might like these other discussions...
· Posts 3 · Viewed 268
· Posts 1 · Viewed 76
· Posts 19 · Viewed 3143 · Likes 1
· Posts 1 · Viewed 95
· Posts 1 · Viewed 81
· Posts 1 · Viewed 127
· Posts 1 · Viewed 136
· Posts 4 · Viewed 1145
· Posts 1 · Viewed 255
· Posts 1 · Viewed 163



Your Banner Here
Travel Partners
Travel House Nepal