[Tutor] problem solving with lists

marcus.luetolf at bluewin.ch marcus.luetolf at bluewin.ch
Sun Mar 20 10:55:27 EDT 2022


Hello Experts and Helpers,
a lot to answer:

yes, I am multi-langual. I should have said  "And other ...............knowledge of other programming  languages but python. 
I have worked several online courses in python (coursera, edx etc.) over the past years,  including most of Alan Gould's 
online tutorial. Therfore, a am still a beginner in python but not a learning beginner.

I am using most oft he recomandations below, stepping back for a break, duck (my wife) method, reducing problem's (mental recursion), even dreaming.  

P.e. I've reduced my problem  from

>all_letters = ‘abcdefghijklmnop’ 
>number_of_lists = 5
>number_of_sublists per list = 4
>number_per_sublist = 4
to
>all_letters = ‘abcdefghi’ 
>number_of_lists = 4
>number_of_sublists per list = 3
>number_per_sublist = 3
to
>all_letters = 'abcdef'.

My "real world problem" to build teams of unique composition ist exactly the same as to build unique
sublists with letters. The latter beeing much easier do handle (typing(errors), readabilty etc.) to me.
My goal was to explain my problem, algorithm, solution steps as precise as possible to avoid confusion.
I might have not succeeded.

dn's 'Results obtained:' (mail 20/03/2022 15.07)  were altered in his mail of  19.03.2022 04:03 resulting in 
the exclusion of shared pairs, what was required. But there was no code offered. 
What means "OP", "32 nicely formated LoC", "PEP-8 spacings" ???

Concerning my definition of "Unique" 
> «Unique» means that other than single items/letters,  pairs of 
> items/letters (pair1, pair2, pair3) can appear only once in all 
> sublists. A sublist could be understood as a combination of
> pair1+pair2+pair3. At the end there should be only 12 sublists
> in 4 lists left.
Which "solution provided-earlier" are you referring to ?

I am very gratful for the hint to use the  intersections method to identify "shared pairs" instead of laboring with indices,
seems rather straightforward.  But for now I cannot see yet how to use it to remove all non-uniques sublists/teams.
SPG exactly describes my goal.
Also for finding a solution without postprocessing but with finding unique sublists/teams from the beginning I have 
no idea at the moment.

But I am very greatfull for this and possibly future exchanges on tutor with you as as Experts and Helpers. 
I have learned a very lot. I hope I belong not to the people who can't do certain things.
Thank you all for your time.
Marcus.

-----Ursprüngliche Nachricht-----
Von: Tutor <tutor-bounces+marcus.luetolf=bluewin.ch at python.org> Im Auftrag von dn
Gesendet: Samstag, 19. März 2022 21:36
An: tutor at python.org
Betreff: Re: [Tutor] problem solving with lists

Marcus,

On 20/03/2022 02.55, marcus.luetolf at bluewin.ch wrote:
> First to dn’s answer:
> 
> I am not an professional programmer. Programming with pyhon is a hobby 
> in the sense of life long learning.
> 
> And other than a course in C I have no knowledge of other programming 
> languages. I am just trying to solve
> 
> my problem with what little I know about python. That’s why I turned 
> to tutor for help. I have found an
> 
> algorithm and all required code steps but the very last one,  
> admittedly helped by most wellcome

This explains a lot - and is partly why you are experiencing so much difficulty!

I'm expecting that you are multi-lingual in spoken languages. You would not learn a new language, let's say Swahili, by taking every word in your native-tongue and translating it, by itself. Dictionaries are useful, but sentences are not mere words strung together. For example, the order of words in an English sentence, and those same words translated one-at-a-time into German, will probably not produce a grammatically-correct sentence. Then there are those ghastly English words which have multiple meanings - depending upon the context of their use.

Even more complicated are idioms and sayings. The New Zealand "yeah, nah" (literally "yes, no", but meaning: I'll pretend to agree, but I
don't) or the American "yeah right" (the exact opposite of what the words 'say', ie this is NOT correct - I don't really believe you), will definitely not convey correct meaning if the translation is merely word-for-word!


May I recommend that you put aside your C-knowledge (don't throw it away), and benefit from the guidance in a 'How to learn Python' book or an online course (many are free)*. One of these will introduce you to the syntax of Python AND the semantics, idioms, etc, in a structured manner. Thus, you won't be left trying to make your own way, without knowing a good path to follow!

* @Alan's messages used to finish with a link to his course. If you ask, perhaps he'll explain why his latest did not...


When you do, you will quickly skim through things like assignment statements, because they will be very familiar to you. However, you will quickly start to notice important differences, eg for-loops are not the same, no matter their appearance. Accordingly, the manner in which one employs a for-loop changes, and with it the idiom - the way one processes items in lists and characters within strings!


> dn’s « definitions » are correct but I reduced the problem solving to
> 
>>all_letters = ‘abcdefghi’ 
>>number_of_lists = 4
>>number_of_sublists per list = 3
>>number_per_sublist = 3

The first step to finding a solution is to understand the problem. It is sad that you have resisted requests to show the 'real world' problem, and thus have reduced the matter to an academic exercise - which is why it seems to be 'homework'!

However, understanding the parameters is a start.


> But dn’s «results obtained»  is not what I need, I replaced them by 
> itertools function combinations.

Sometimes it is a good idea to step-back from the problem. Some suggestions the psychologists and neuroscientists offer are: to take a shower, or a walk, watch TV, read a book - anything to get the problem out of the 'front' of your head. Of course it won't be completely 'gone'. The sub-conscious will still be 'turning it over in your mind'.
This process of looking at things in a different way can yield alternate approaches! Thus, people often saying something like: "the answer 'came to me' while I was in the shower"!


You asked for help - and that is what at least three of us have been rendering. Yet, here you have said "is not what I need". What does that mean? What is in your head, that is not in mine? How do you move/copy this knowledge of what you need, from your head to mine? Have you done so?

The distinct request was: "Are these correct? If not, please advise which part is incorrect?"

The first part was answered. What of the second?

In what way were the answers incorrect? In what way was the specification/problem-statement not fulfilled?


Have you invested time and effort to help the person who has given up free-time to help you?
(see also @Dennis' comments, despite the hours he must have given already)

Perhaps that idea of 'taking a break' is needed, so that you can be as helpful as they, to the people who are being helpful to you?


> dn’s last section I don’t understand.

Again, what you say is understandable, but *why*? If you indicate the part that you don't understand, then we can help your "life long learning"...

Has this abrupt dismissal, or rejection, helped you? Helped me?


> My problem ist to create a set of unique sublists of 3 items/letters 
> out of a list of 9 items/letters, later to be extended to sublists of 
> 4 items/letters out of a list of 16 items/letters.

This statement: "3 items/letters out of a list of 9 items/letters" does
*not* appear in the original post. Why? Why not?

Can we solve one problem at a time, and then move-on to the next? You say "later", which may be the case inside your own head. However, in our context, the original post has us thinking of 'the solution' as four sub-lists of four items - and that problem is not yet solved.


An English idiom for causing such confusion is that you are "moving the goal-posts". Generally regarded as either cheating, or at least causing confusion. Do you mean to do this to us?


Yes, "three" or "four", I (think I) can see that they are similar problems - strangely enough, this is why I wrote the "definitions" at the beginning of the code, rather than 'burying' the fours and the five as "magic numbers" within the algorithm!

Such is a good programming practice, because it enables the very flexibility of sizes and selections, your second problem (may) requires.


> I am using letters as items for the sake of readability. Once the code 
> works letters will be substituted by names of people for the final 
> goal is to set up  «unique» teams.
> 
> «Unique» means that other than single items/letters,  pairs of 
> items/letters (pair1, pair2, pair3) can appear only once in all 
> sublists. A sublist could be understood as a combination of
> pair1+pair2+pair3. At the end there should be only 12 sublists
> in 4 lists left.

Which leaves me baffled. The solution provided-earlier appears to do exactly that. There is no repetition of letter-combinations/team-members' names.
(or perhaps I can't see that there are*, and need to be shown...)

* am in-recovery from a recent eye operation

So, exactly why did you reject it?
(and I'm repeating an earlier question)


Similarly, and further to my earlier comment about "real world", @Dennis' explanation of 'golfers and schoolgirls' suddenly brought the problem into focus - I remembered staff at our school (many, many, years
ago) trying to do exactly this sort of thing - otherwise the strong players would always want to play together, and the unskilled players would end-up (always) on the losing team. Learning to deal with this (what seemed like a frustrating imposition, at the time) taught me that each person can do certain things (and not others), and thus the concept of "the right man for the job" (today: updated to an "equal-opportunities" attitude)

Thanks @Dennis!


A key to "learning" (which includes learning about/understanding the problem to be solved) is to start from something we know, and then step (one small pace) into the unknown. Thus, we learn something 'new' *and* absorbing it, we also align that knowledge in our minds. For example, to know when we can use it/employ such a solution! Now that I understand that the letters represent names of people, my confidence has grown...


Speaking of "solutions". There is often more than one way to solve a problem. Twee example: 1 + 2 == 2 + 1. The idea of 'stepping back' (as
above) often enables one to realise that 'there's another way'. As mentioned previously, we could either generate every "combination" and then trim those with unacceptable repetitions, or we could generate unique combinations in the first place.
(and maybe there are other approaches)

Persisting with a solution (that isn't working) without stopping to consider such, reminds me of another idiom: "flogging a dead horse" - and we wouldn't want to be unkind to animals, would we?

So, please take a breath and relax. Then instead of rushing to code/to reply to email, consider what you have been offered, answer questions (first for yourself, and only later for us), and look at the problem and the solution(s) - from all angles...


> Sorry for the length of this replay, Marcus.

...


Nobody here is 'against' you. Please avoid letting your frustrations communicate the negativity towards your helpers (which has been happening)!

Please ask yourself: if someone has taken a chunk of time to consider the problem and (attempt to) offer help, should I give a similar amount of time, care, and respect; in response?
--
Regards,
=dn
_______________________________________________
Tutor maillist  -  Tutor at python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor



More information about the Tutor mailing list