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

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -