Hello, checkiomates🐱👤!
This week's digest streamlines your workflow, from a rock-solid Django setup to mastering type hinting for decorators and the power of Enums for constants. We conclude with a logic-heavy mission to reorganize cafeteria seating with minimal student swaps.
💡TIP
At your profile, after clicking on big percent number of your progress, you may see module and methods you have already used in your shared solutions. If you want to discover all CheckiO features, visit our tutorial. It's a longread, but it's worth it!
🏁 MISSION
Friends At Cafeteria by freeman_lex -
The school cafeteria has a long rectangular table. Students can sit along long sides at the table and each student sits facing a student sitting on the opposite side of him. Given the initial positions where the members of the group are seated, determine the minimum number of exchanges necessary between students sitting in neighboring chairs so that each member of the group of friends sits in front of another member of the group.
friends([0, 1, 0, 0, 1, 0], [1, 0, 1, 0, 0, 0]) == 3 friends([0, 0, 1, 0, 1, 1, 0, 0, 0, 0, 1, 0], [0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1]) == 7 friends([1, 1, 1, 1, 0, 0, 0, 0, 0], [1, 0, 0, 1, 0, 1, 0, 0, 1]) == 10
📖 ARTICLES
How to Create a Django Project -
Learn how to create a Django project and app in clear, guided steps. Use it as a reference for any future Django project and tutorial you’ll work on.
How to Type Hint a Decorator in Python -
Writing a decorator itself can be a little tricky, but adding type hints makes it a little harder. This article shows you how.
Need a Constant in Python? Enums Can Come in Useful -
Python doesn’t have constants, but it does have enums. Learn when you might want to use them in your code.
👩💻CODE SHOT
What do you think the following code does?
def checkio(instructions: str) -> tuple[int, int] | list[int]:
move = {"f": 1, "b": -1, "l": -1, "r": 1}
x = y = 0
for i in instructions:
x += move[i] * (i in "lr")
y += move[i] * (i in "fb")
return x, y
🙌 Thanks for your attention! Hope to meet you at CheckiO, as well as at our Instagram and Twitter! We are really interested in your thoughts! Please, leave a comment below! ⤵
