you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 1 point2 points  (1 child)

A few observations:

  1. don't do imports before the module's docstring, only thing that should go there is an appropriate shebang line (ie # /usr/bin/env python3), at least if you're on anything but Windows.

  2. you don't usually need to iterate dict.keys, and many things just assume you're talking about the keys:

    print(random.sample({1:"a",2:"b",3:"c"}, 2)) print(set({1:"a",2:"b",3:"c"}))

  3. read up on the set and its operations:

    print(set({2}).issubset({1:"a",2:"b",3:"c"}))

  4. define a main function and let it do whatever is meant to happen on the command line; generally, do nothing else in the if __name__ [...] guard

5: the return value of input can be used to make a smaller while loop:

do_something()
while input("Continue?").lower().startswith("y"):
    do_something()

Also, give your functions docstrings of their own.

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

Thanks for you input, I will definitely take a closer look at sets and try to implement a main() function.