From 568f46ec263817025614041a0ef01113ee33dd67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20H=E1=BB=93ng=20Qu=C3=A2n?= Date: Wed, 24 May 2023 16:32:17 +0700 Subject: [PATCH] Improve Python code --- python/main.py | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/python/main.py b/python/main.py index d5619fa..49aea5e 100644 --- a/python/main.py +++ b/python/main.py @@ -4,15 +4,9 @@ async def perform_task(): await asyncio.sleep(10) - -async def main(num_tasks): - tasks = [] - - for task_id in range(num_tasks): - task = asyncio.create_task(perform_task()) - tasks.append(task) - - await asyncio.gather(*tasks) +async def main(num_tasks: int): + gen = (asyncio.create_task(perform_task()) for i in range(num_tasks)) + await asyncio.gather(*gen) if __name__ == "__main__": if len(sys.argv) > 1: