TGViewer
Python tests Python tests @python_testit · 6.9K subscribers
Post #1161 1.91K
🧠 Python-хитрая задача + решение

🖍️ Условие:
У тебя есть список логов (user, login/logout).
Найди тех, кто зашел, но не вышел.

📜 Пример:

logs = [
("alice", "login"),
("bob", "login"),
("alice", "logout"),
("dave", "login"),
("bob", "logout"),
("carol", "login"),
("dave", "logout")
]


________
💻 Решение:

from collections import defaultdict

def find_stuck_users(logs):
counter = defaultdict(int)
for user, action in logs:
if action == "login":
counter[user] += 1
elif action == "logout":
counter[user] -= 1
return sorted([user for user, count in counter.items() if count > 0])


🛠Ответ: "carol"

#Python #Challenge #DevPuzzle

@python_job_interview
More from @python_testit
  1. Sep 6, 2026🐍 Python считает эти даты равными. Хотя между ними целый час В ночь перевода часов время…
  2. Aug 14, 2026Post #1269
  3. Aug 14, 2026photo post
  4. Aug 14, 2026🔥 Python + AI без игрушечных демок. Курс для тех, кто хочет собирать рабочие системы. Ste…
  5. Jul 22, 2026Post #1266
  6. Jul 22, 2026photo post
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →