(Mar-28-2022, 07:10 PM)deanhystad Wrote: Still not understanding. If c1 is a Counter, x = c1.values() will be a sequence of numbers (actually a generator).
It's not a generator, nor is it a
sequence (it doesn't support sequence operations like subscripting). It is a "dictionary values
view object" (try saying that five times fast!). View objects:
- provide a live read-only proxy to the Counter;
- (usually) with a set-like interface;
- and are iterable.
The values view is not set-like, but the other two views (
dict.keys()
and
dict.items()
) are.
In practice, we can treat views as iterables: we can iterate over them. One difference between a view and a generator is that you don't have to call the view method twice to iterate over it twice:
Output:
>>> view = {'spam': 1, 'eggs': 2}.values()
>>> list(view) # iterate over it once
[1, 2]
>>> list(view) # iterate again
[1, 2]
With a generator you have to call the generator again to refresh the state and start it over.
(Mar-28-2022, 09:03 PM)CompleteNewb Wrote: in case you haven't noticed, answering question is a voluntary act
Yes it is. Do you want answers or not? If you don't, why are you bothering to ask the question? And if you do, you shouldn't bite the hand that feeds you. We're not being difficult to be obnoxious. We're trying to understand your problem so we can help.
It's not up to us to go the extra mile to try to work out what you want, we're not being paid. We're donating our time and effort for the good of the community, and to pay back those who helped us when we were newbies. Be respectful of our time and effort, if only because that will maximise the chances of you getting the help you need.
Help us to help you. The
better the questions you ask, the more likely we are to
give effective answers.
Or you can be snarky, and get ignored, or worse, some vindictive smart arse will give you
bad answers.
(Once, many years ago, I saw somebody -- not me, I promise -- give a really obnoxious
help-vampire a solution that was obfuscated and destructive, so that if they actually ran the code -- which of course they didn't, help-vampires rarely do -- it would have erased the files in their home directory. Ouch. That's not nice.)
(Mar-28-2022, 10:13 PM)CompleteNewb Wrote: The thing is that even when i ask a question that other people understand, you find a way to bitch about it
Who are these people who are understanding this question? Only two people have even attempted to help you in this thread, me and deanhystad, and you've just told one of them to bugger off. Are you sure that was wise?
If you think that there are other people who understand what you are attempting to do in your code, you could wait for them to answer. Or you could remember that we're not mind-readers, and
help us to help you.
My time is not unlimited. I will make one more effort to re-read your posts in this thread and try to decipher what you are trying to do, after which the ball is in your court.
Its still not clear what you want, at one point you said that all of the values are always 1, and you want to get
x = 1
, but then in another response you want to get
x = [2,2]
.
So I'm deeply confused, but I'm going to try to take a Hail Mary shot and hope for the best. Does this help?
Output:
>>> from collections import Counter
>>> c = Counter([1, 2, 3, 1, 1, 2, 1])
>>> c
Counter({1: 4, 2: 2, 3: 1})
>>> values = c.values()
>>> values
dict_values([4, 2, 1])
>>> values = list(c.values())
>>> values[0]
4
If that doesn't help, I am totally out of ideas.
And I have absolutely
no clue at all how this relates to your comment that "what i'm trying to do is to compare pairs and triple and quadruples so that if i have a pair, i get returned the triple equivalent because the pair is contained in the triple and the triple is only missing one element, but not the quadruple because it is missing two elements".