0
0

More than 3 years have passed since last update.

python typing example

Posted at

after set python.linting.mypyEnabled to true(not to sell you have Pylance in place) you are equipped with typing


import sys
from typing import Tuple, Union

global nums


def sum2(start: int, end: int, target: int) -> Union[Tuple[int, int], None]:
    seen = set()
    for i in range(start, end):
        n = nums[i]
        if target - n in seen:
            return (n, (2020 - n))
        else:
            seen.add(n)
    return None


if __name__ == "__main__":
    nums = sorted(map(int, sys.stdin))
    end = len(nums)
    for i, num in enumerate(nums):
        ret = sum2(i, end, 2020 - num)
        if ret is not None:
            print(num * ret[0] * ret[1])

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0