def create(ids):
policy = {
'Statement': []
}
for i in range(0, len(ids), 200):
policy['Statement'].append({
'Principal': {
'AWS': list(map(lambda id: f"arn:aws:iam::{id}:root", ids[i:i + 200]))
}
})
return policy
when I make a function call to this method create({'1','2'}) I get an TypeError: 'set' object is not subscriptable error on line
'AWS': list(map(lambda id: f"arn:aws:iam::{id}:root", ids[i:i + 200])).
Coming from a java background, is this somehow related to typecasting?
Does the error mean that I'm passing a set data structure to a list function?
How could can this be resovled?
sets are unordered therefore do not support indexing and slicing. Why do you have to pass asetto this function?ids[i:i + 200]? Sets can't be indexed as the error says. Maybe put that into a list first or useislice? Indexing a set is diallowed likely because sets aren't ordered, so the element at any given index is essentially arbitrary.setobject to a function that will try to index that object, which set objects don't support