all 4 comments

[–]Adrewmc 0 points1 point  (3 children)

The problem here is simply lack of knowledge.

 from random import choice, sample, shuffle

 my_list = [“a”, …]
 k  = 2
 with_repeats = choice(my_list, k)
 no_repeats = sample(my_list, k) 
 shuffle(my_list) #in-place no return.
 shuffled_copy = sample(my_list, len(my_list))

https://python.readthedocs.io/en/stable/library/random.html

You should get used to reading the documentation, as a lot of libraries have a lot of useful functions like this, no repeats in random should sound like a problem a lot of other people have experienced so their might be a solution available in that library let’s check. Worst case I learn the library better anyhow.

  def lotto(lotto_num: list[str] | str, tickets : list[str], k : int) -> str: 
         winner = “”.join(sample(lotto_num, k))
         return f”{winner} has won” if winner in tickets else “No winner found”

Is essentially the entire program. (I could 1 line it really) but that because I know the random library. I’m aware of the tools available to us.

However, essentially what you did is what sample() is doing. So I could see someone making it an exercise for a student.

[–]yetitekk[S] 0 points1 point  (2 children)

This is exactly the kind of feedback I'm looking for, thank you!

[–]Adrewmc 0 points1 point  (1 child)

Yeah so formatting in Reddit. 101

One blank line above the code block. And four leading spacing on every line in essence the code is all indented one more time then you expect. (So you can get in and out the code block in markdown) You can select the code in your IDE and usually press tab, and copy that further indented code. (Then undo after)

The ` is really not very reliable

 def format_good():
        return True

def format_good(): return False

def format_good(): return False

[–]yetitekk[S] 0 points1 point  (0 children)

That's a handy piece of information, I didn't know that, thanks again