-
💙 Let's write python code efficiently and elegantly
💜 编写高效,优雅的python代码!
-
❤️ Python is one of the most popular programming languages, and it's easy to understand. It's assumed that you're able to write python code, but the problem lies in how to write it well, namely efficiently, elegantly, easy to read for others and name the variable properly.
-
💚 Python是最受欢迎的编程语言之一,易上手,好理解。很多人可以编写一些能够运行Python代码,但是我们希望代码能运行的更加高效,写的更加规范, 易读,这也是本repo的目的所在。
一些参考资料
- 关于python效率和性能的分析 [python性能优化]
- 定位程序性能瓶颈 [Python 代码性能优化技巧]
repo主要关注对于Python常用模块提高效率方法的介绍,以及代码的常用规范,持续更新,欢迎Star, Issue, Pull requests
- 💉 numpy
- 💧 string
- 🐮 list
- 🍺 copy
- 👅 built-in funcs
- 🐶 name
- ⭐ to be continued
For example, original code is:
for s in str_list:
str_a += s
.join()
is more efficient than +=
for string connection, so it's better to write like:
str_a = ''.join(a)
The actual running time(len(a)=1e8) is:
time for +=: 2.5960795879364014s
time for join: 0.357041597366333s
Another example:
Class appletree():
def leaf():
pass
We usually use Camel-Case
in class name, that is, it's better to define the class like this:
Class AppleTree():
def leaf():
pass