Re: Find word by given characters

2020-11-01 Thread Bischoop
On 2020-11-01, Bischoop  wrote:
> I'm working on a script i which user inputs letters and then a printed
> words containing those letters. The scripts works however I can't solve
> one problem , it prints also words in which these letters occur more 
> than once.
> ---
> Fore example:
> Letters: at
> Output: auto, autobahn.
> ---
>
> I supposed to not print word: "autobahn" because I've given it only one
> letter "a".
>

Problem's solved.


for word in words:
if all(word.count(x) == letters.count(x) for x in letters):
print(word)
-

Thanks for suggestions, I didn't had to use counter but going to look
into as it seems useful and interesting.

Thank You
-- 
https://mail.python.org/mailman/listinfo/python-list


Extending collections.Counter with top_n() to return elements by rank

2020-11-01 Thread Bora
collections.Counter has most_common([n]) method which returns the most
common n elements of the counter, but in case of a tie the result is
unspecified --- whereas in practice the order of insertion breaks the
tie. For example:

>>> Counter(["a","a","b","a","b","c","c","d"]).most_common(2)
[('a', 3), ('b', 2)]

>>> Counter(["a","a","c","a","b","b","c","d"]).most_common(2)
[('a', 3), ('c', 2)]

In some cases (which I believe are not rare) you would like to break
the tie yourself or get the top elements by *rank*. Using our example:

RankElements
   0{"a"}
   1{"b", "c"}
   2{"d"}

I propose a new method top_n(n) that returns the top elements in the
first n ranks. For example:

>>> Counter(["a","a","b","a","b","c","c","d"]).top_n(0)
[('a', 3)]

>>> Counter(["a","a","b","a","b","c","c","d"]).top_n(1)
[('a', 3), ('b', 2), ('c', 2)]

>>> Counter(["a","a","b","a","b","c","c","d"]).top_n(2)
[('a', 3), ('b', 2), ('c', 2), ('d', 1)]

>>> Counter(["a","a","b","a","b","c","c","d"]).top_n(99)
[('a', 3), ('b', 2), ('c', 2), ('d', 1)]

>>> Counter(["a","a","b","a","b","c","c","d"]).top_n(-1)
[]

Some points to discuss:

 * What the return type should be? A list of tuples like most_common()
   or List[Tuple[int, List[T]] that conveys the rank information too?
   Each tuple is a rank, whose first element is the frequency and
   second element is the list of elements. E.g. [(3, ['a']), (2, ['b',
   'c']), (1, ['d'])]
 * Rank starts at 0 or 1?
 * Shall negative numbers raise an exception or return an empty list
   like most_common()?

I would love to hear your opinion on this, and if there is interest, I
am happy to implement it too.

Regards,

Bora M. Alper
https://boramalper.org/


-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Best way to determine user's screensize?

2020-11-01 Thread songbird
Grant Edwards wrote:
> On 2020-10-31, songbird  wrote:
...
>> do you object to a window being put in the approximate
>> center of the screen?
>
> YES. I've configured my window manager so windows start up where I
> want them to start up. It's none of the application's business where
> it's window is.
>
> When developing an application, try to remember IT'S NOT YOUR
> COMPUTER.

  certainly it isn't but it is my game and i kept it
simple.  if people don't like it then they can find
something else to play.  i'm good with that, but the
next time i get back to making changes i'll see what
i can figure out for saving the location where someone
has moved it.


  songbird
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Best way to determine user's screensize?

2020-11-01 Thread songbird
Mats Wichmann wrote:
> On 10/30/20 6:47 PM, songbird wrote:
...
>>   do you object to a window being put in the approximate
>> center of the screen?
>
> Absolutely!  I'm fighting that on a system which, after an update,
> insists on opening new terminal windows centered - some recent policy
> change is now doing that instead of where the same thing was placed the
> last time it was open (I assume I'll find the knob for that eventually).
>  As others have said, there's no one-size-fits-all; on a big screen you
> certainly don't want the same things as on a phone, where "take over the
> whole screen" might indeed be the only thing that makes sense.

  to keep a program simple i made it to open in the center.
if i ever get back to it i'll have to figure out how to ask
the windowing system what it wants to do for placement and
then store that location as part of the configuration if the
person moves it.

  i don't use multiple screens yet nor do i mind moving an
item once when i'm starting up, but i could see where if 
there are a lot of windows that it would be annoying to 
have to move all of them.


  songbird
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Find word by given characters

2020-11-01 Thread duncan smith
On 01/11/2020 13:38, Bischoop wrote:
> On 2020-11-01, Bischoop  wrote:
>> I'm working on a script i which user inputs letters and then a printed
>> words containing those letters. The scripts works however I can't solve
>> one problem , it prints also words in which these letters occur more 
>> than once.
>> ---
>> Fore example:
>> Letters: at
>> Output: auto, autobahn.
>> ---
>>
>> I supposed to not print word: "autobahn" because I've given it only one
>> letter "a".
>>
> 
> Problem's solved.
> 
> 
> for word in words:
> if all(word.count(x) == letters.count(x) for x in letters):
> print(word)
> -
> 
> Thanks for suggestions, I didn't had to use counter but going to look
> into as it seems useful and interesting.
> 
> Thank You
> 

But this generates the letters counts for each word. They only need to
be generated once (outside the for loop). And using count requires
iterating over the letters / words for each x in letters (rather than
once). For a large enough collection of words you'd notice the difference.

Duncan
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: GUI: I am also looking for a nudge into the best (GUI) direction.

2020-11-01 Thread Greg Ewing

On 1/11/20 5:43 pm, Michael Torrie wrote:

In C# world, WinForms is often used, but it's not "native" win32
widgets.  Widgets are implemented in managed code (according to
Wikipedia) that draw themselves using the theming dll so they look
native, or at least look somewhat consistent with regards to button
styles, fonts, colors, etc.


Well, Microsoft has a lot more resources than your typical third
party GUI toolkit developer to spend on re-doing everything
periodically. It still make sense to let them do the hard work
instead of replicating it all yourself.


In fact I know of very few
Windows applications that use exclusively the basic native widget set
from win32.


Which is understandable -- the raw Windows GUI API is pretty
cruddy and doesn't do a lot of what one expects from a modern
GUI toolkit.

But I still think it's better to base your UI on one of the
standard offerings from Microsoft such as WinForms rather than
rolling your own.

--
Greg
--
https://mail.python.org/mailman/listinfo/python-list