将Python内置函数名称替换为新函数。

huangapple go评论82阅读模式
英文:

Substituting Python built-in function name to the a new function

问题

我在这个平台上提出了我的第一个问题。在用Python解决算法问题时,我遇到了一个问题,但我不知道如何在Google上找到相关的官方文档。你能帮助我吗?

这是下面的代码。

input = stdin.readline

T = int(input())

因为速度的原因,我将使用stdin.readline()函数替代input()函数。
我知道它可以正常工作,没有语法问题,但我不知道如何找到相关的概念或文档。

英文:

I'm leaving my first question on this platform. I got a question while solving algorithm problems with Python, but I don't know how to find related official documents on Google. Can you help me?

This is the code down there.

input = stdin.readline

T = int(input())

Because of the speed, I'm going to replace the input() function with stdin.readline().
I know it works without any grammatical problems, but I don't know how to find relevant concepts or documents.

答案1

得分: 1

我相信你想要使用类似这样的stdin.read函数:

from sys import stdin
print("\n".join(stdin.read().split()))

input = stdin.readline

已经将输入函数重命名为stdin.read,尽管性能差异应该可以忽略不计。

我建议你使用一个不同的解释器,比如pypy3,或者使用cpython来加速你的程序,并改进你程序的其他部分。或者如果你认为你的算法已经处于最优状态,那就切换到另一种编程语言。

英文:

I believe you want to use the stdin.read function similar to this:

from sys import stdin
print("\n".join(stdin.read().split()))

and the

input = stdin.readline

have already renamed the input function to be the stdin.read

,dough the performance difference should be negligible.

I would suggest you use a different interpreter such as pypy3 or use cpython to speeding your program and
improve the other parts of your program or if you think your algorithm is in the most optimal state possible then just switch to an other programming language.

huangapple
  • 本文由 发表于 2023年1月9日 16:57:52
  • 转载请务必保留本文链接:https://go.coder-hub.com/75054981.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定