The code below gets the index of matching values:
x = ["Moon", "Earth", "Jupiter", "Neptune", "Earth", "Venus"]
get_indexes = lambda x, xs: [i for (y, i) in zip(xs, range(len(xs))) if x == y]
print(get_indexes("Earth", x))
The code below extracts the peaks satisfying the conditions:
intensitySortedPeaks = sorted(peaks, key=lambda p: p.Intensity, reverse=True)
for i in range(len(intensitySortedPeaks)):
testMass = intensitySortedPeaks[i].MZ + 1.0033
results = [p for p in intensitySortedPeaks if abs(GetPPMError(p.MZ,testMass)) < 10]
###how do we get the indexes saved as indeResults
How do I get the indices of the elements that were stored in the results variable. I want to remove those elements from the original intensitySortedList in the loop
How do I modify the above code to achieve this task?
If only want indices of matching items then try:
def indices_satisfying(fn, lst):
return [index for index,x in enumerate(lst) if fn(x)]
If you want to remove the satisfying elements do
def removing_satisfying(fn, lst]:
return [x for x in lst if not fn(x)]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.