Here’s a snippet from my Python Template.
from sys import stdin, stdout, stderr, setrecursionlimit from math import pi, sqrt, gcd, ceil, floor, log2, log10, factorial from math import cos, acos, tan, atan, atan2, sin, asin, radians, degrees, hypot from bisect import insort, insort_left, insort_right, bisect_left, bisect_right, bisect from functools import reduce from itertools import combinations, combinations_with_replacement, permutations from fractions import Fraction from random import choice, getrandbits, randint, random, randrange, shuffle from re import compile, findall, escape, search, match from statistics import mean, median, mode from heapq import heapify, heappop, heappush, heappushpop, heapreplace, merge, nlargest, nsmallest from collections import deque, OrderedDict, defaultdict from collections import Counter, namedtuple, ChainMap, UserDict, UserList, UserString # from numpy import dot, trace, argmax, argmin, array, cumprod, cumsum, matmul
It is of course better to write them like this
Better way (to save time)
import sys import math import bisect import functools import itertools import fractions import random import re import statistics import heapq import collections # import numpy
One of the best methods to import
Best way (saves time)
from sys import * from math import * from bisect import * from functools import * from itertools import * from fractions import * from random import * from re import * from statistics import * from heapq import * from collections import * # from numpy import *
Coming to the performance issues, I am still unable to figure out which one is the best. Can anyone who is familiar with Python share their thoughts or maybe along with proofs (ex: execution times of various codes).
PS: Consider only the performance during execution, ignore the time taken to type