python - How to get index of element in Set object -
i have this:
numberlist = {} item in results: data = json.loads(item[0]) if data[key] in itemlist: numberlist[itemlist.index(data[key])] += 1 print numberlist
where itemlist 'set' object. how can access index of single element in ?
a set unordered collection of unique elements. so, element either in set or isn't. means no element in set has index.
consider set {1, 2, 3}
. set contains 3 elements: 1, 2, , 3. there's no concept of indices or order here; set contains 3 values.
so, if data[key] in itemlist
returns true
, data[key]
element of itemlist
set, there's no index can obtain.
Comments
Post a Comment