MCPcopy Index your code
hub / github.com/RustPython/RustPython / elements

Method elements

Lib/collections/__init__.py:645–664  ·  view source on GitHub ↗

Iterator over elements repeating each as many times as its count. >>> c = Counter('ABCABC') >>> sorted(c.elements()) ['A', 'A', 'B', 'B', 'C', 'C'] Knuth's example for prime factors of 1836: 2**2 * 3**3 * 17**1 >>> import math >>> prime_factors = C

(self)

Source from the content-addressed store, hash-verified

643 return heapq.nlargest(n, self.items(), key=_itemgetter(1))
644
645 def elements(self):
646 '''Iterator over elements repeating each as many times as its count.
647
648 >>> c = Counter('ABCABC')
649 >>> sorted(c.elements())
650 ['A', 'A', 'B', 'B', 'C', 'C']
651
652 Knuth's example for prime factors of 1836: 2**2 * 3**3 * 17**1
653
654 >>> import math
655 >>> prime_factors = Counter({2: 2, 3: 3, 17: 1})
656 >>> math.prod(prime_factors.elements())
657 1836
658
659 Note, if an element's count has been set to zero or is a negative
660 number, elements() will ignore it.
661
662 '''
663 # Emulate Bag.do from Smalltalk and Multiset.begin from C++.
664 return _chain.from_iterable(_starmap(_repeat, self.items()))
665
666 # Override dict methods where necessary
667

Calls 2

from_iterableMethod · 0.80
itemsMethod · 0.45