I have something like this:
numberList = {} for item in results: data = json.loads(item[0]) if data[key] in itemList: numberList[itemList.index(data[key])] += 1 print numberList
where itemList is 'set' object. How can I access index of single element in it ?
There is no index attached to any element in a python set. So they do not support any indexing or slicing operation.
A set is just an unordered collection of unique elements. So, an element is either in a set or it isn't. This means that no element in a set has an index.
By contrast, Sets are a keyed collection. Instead of using indices, Sets order their data using keys. A Set's elements are iterable in the order of insertion, and it cannot contain any duplicate data.
A set is just an unordered collection of unique elements. So, an element is either in a set or it isn't. This means that no element in a set has an index.
Consider the set {1, 2, 3}
. The set contains 3 elements: 1, 2, and 3. There's no concept of indices or order here; the set just contains those 3 values.
So, if data[key] in itemList
returns True
, then data[key]
is an element of the itemList
set, but there's no index that you can obtain.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With