2019 年 stackoverflow 网站最受欢迎的 20 个 Python 问题

在最新一期的“Python开发者周刊”(Pycoder's weekly)里,我看到一则有意思的分享,故转出来分享给大家。

该分享来自是一份”python weekly reports“,统计了 2019 年里 stackoverflow 网站上支持数最高的 20 个问题。问题列表如下(方括号中的两个数字是其支持数与回答数):

  1. Why does Python's hash of infinity have the digits of π? - [236/3]
  2. Is there a more elegant way to express ((x == a and y == b) or (x == b and y == a))? - [105/10]
  3. Why can I use a list index as an indexing variable in a for loop? - [92/6]
  4. Why does (inf + 0j)*1 evaluate to inf + nanj? - [93/4]
  5. Why is f'{{{74}}}' the same as f'{{74}}' with f-Strings? - [88/1]
  6. Why does b+=(4,) work and b = b + (4,) doesn't work when b is a list? - [75/7]
  7. Why does Python start at index -1 (as opposed to 0) when indexing a list from the end? - [79/7]
  8. Why is TensorFlow 2 much slower than TensorFlow 1? - [104/2]
  9. Randomness of Python's random - [70/4]
  10. Why does Python allow out-of-range slice indexes for sequences? - [72/2]
  11. Unexpected behaviour with Python generator - [57/8]
  12. What exactly is meant by "partial function" in functional programming? - [55/3]
  13. What does a yield inside a yield do? - [56/4]
  14. Issues implementing the "Wave Collapse Function" algorithm in Python 2.7 - [52/2]
  15. Should linear read-shuffled write always be faster than shuffled read-linear write? (Was: Why is fancy assignment slower than fancy lookup?) - [53/5]
  16. How to write 2**n - 1 as a recursive function? - [49/7]
  17. Why is a for loop so much faster to count True values? - [53/5]
  18. Is there a difference between board[x, y\] and board[x][y] in Python? - [47/6]
  19. Why was p[:] designed to work differently in these two situations?- [51/6]
  20. Jupyter notebook: No connection to server because websocket connection fails - [46/4]

不用怀疑,这些内容的支持数和回答数就是那么少。不过也需注意,它统计的是问题本身的支持数,而不是回答的支持数(尽管回答的支持数也很少)。

还有一点需注意,这份报告并非 stackoverflow 网站的官方报告,而且文中也未说明统计口径与筛选标准,所以我们姑且一看。

有些问题可能挺怪的,或者平时不大可能考虑到,比如关于列表的两个问题:为什么从列表末尾查找时是从 -1 开始?为什么列表的切片允许越界?

不少回答都挺有专业精神,往往会带来新的视角和知识信息。比如,关于列表的 -1 索引问题,高票回答中提到了“~”运算符,有这样的用法:

arr = ["a", "b", "c", "d"]
print(arr[~0])   # d
print(arr[~1])   # c

让人眼前一亮!

还有一个问题是:如何优雅地计算 ((x == a and y == b) or (x == b and y == a)) 这个形式的结果?

高票回答是这样:

初一看,就像看人变戏法一样……

其它问题和回答就不一一说明了,建议感兴趣的同学按图索骥,按部就班,顺藤摸瓜,顺手牵羊……

链接清单:

https://python-weekly.blogspot.com/2020/01/20-best-python-questions-at.html?m=1

[1] http://stackoverflow.com/questions/56227419

[2] http://stackoverflow.com/questions/58435645

[3] http://stackoverflow.com/questions/55644201

[4] http://stackoverflow.com/questions/58031966

[5] http://stackoverflow.com/questions/59359911

[6] http://stackoverflow.com/questions/58259682

[7] http://stackoverflow.com/questions/55684960

[8] http://stackoverflow.com/questions/58441514

[9] http://stackoverflow.com/questions/55934019

[10] http://stackoverflow.com/questions/54613753

[11] http://stackoverflow.com/questions/54245618

[12] http://stackoverflow.com/questions/58339040

[13] http://stackoverflow.com/questions/55922302

[14] http://stackoverflow.com/questions/57049191

[15] http://stackoverflow.com/questions/54782033

[16] http://stackoverflow.com/questions/58378549

[17] http://stackoverflow.com/questions/56288015

[18] http://stackoverflow.com/questions/57351363

[19] http://stackoverflow.com/questions/56782148

[20] http://stackoverflow.com/questions/54963043

公众号【Python猫】, 本号连载优质的系列文章,有喵星哲学猫系列、Python进阶系列、好书推荐系列、技术写作、优质英文推荐与翻译等等,欢迎关注哦。

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • ‘再不疯狂我们就老了’ 我在很多朋友的qq空间或者是朋友圈都能看到这句话。可是又有谁真正的实践了呢?大多数朋友都可...
    想要飞的猪阅读 810评论 1 1
  • 下定决心要从技术转型走上项目管理的道路,由好兄弟推荐,准备报考PMP,走出的第一步。 为了督促自己学习,从来只看不...
    风萧笑阅读 359评论 0 0
  • php mysql 生成排名 方法一:直接使用mysql中的函数 这种方法比较省代码,但是不易读,查询效率也较低 ...
    拾大花sdf阅读 706评论 0 0
  • 看到言言老师的视觉笔记,手帐被种草。正好临近过年工作没那么忙,重拾简笔画的乐趣。 这是元旦后照葫芦画瓢的手绘。 模...
    胡小卷阅读 433评论 0 8

友情链接更多精彩内容