I have the following piece of code:
def getresult (someset):
result = []
index = 0
for key, value in mydict.items():
if someset.issubset(value):
result.append(key)
while (len(result)<10):
index = index+1
someset = someset[index:]
getresult(someset)
return result
The idea is that I want to find out if someset is a subset of some list. If it's not, I want to slice the set until I get results (if it gets to the point where the set only contains one element, results are bound to be found, so endless looping shouldn't be a problem here).
The code above gives me an error: TypeError: 'set' object has no attribute 'getitem' Which, I assume, means that I'm not supposed to use a variable name inside the slice.
- Is it possible to increment a slice?
- If not (or if you believe that slicing won't get the result I'm expecting anyway), is there another way I can loop through a set, ignoring one more element on each loop?