Home > other >  List index value solving continuously
List index value solving continuously

Time:10-02

 

A=[6, 7, 8]
B=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

Print (set) (a). Issubset (set) (b))
Print (set) (a). Issuperset (set) (b))




I hope that the result is: when a value exists in b, return True;

Issubset:
I try to use issubset, certainly can return I will for the first time as a result, but I try to modify a=[6, 7, 3], according to my logic should be returns False, because the data in the b didn't found that 100% of continuity, issubset returns a True as a result, thus, issubset element without considering whether there is continuity, as long as all the individual returns True, there's a vice False, this is not what I want;

Issuperset:
The basic fee, are False

Finally, there is so little amount of data that can be used for judging by comparison, but my side real scene data volume is very big, the original is a less then tens of thousands, of hundreds of thousands of more, with the for efficiency is very low, please everyone a great god rescue,

CodePudding user response:

Don't for, try the while
There's no need to check out, as long as the match, the stops and returns, reference
 a=[6, 7, 8] 
B=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

I=0
Match=False
Lena=len (a)
Bound=len (b) - Lena + 1
While (not match and I & lt; Bound) :
Match=a==b [I: (I) + Lena]
I +=1
Print (match)


  • Related