2019 年 stackoverflow 網站最受歡迎的 20 個 Python 問題

在最新一期的「Python開發者週刊」(Pycoder's weekly)裏,我看到一則有意思的分享,故轉出來分享給你們。html

該分享來自是一份」python weekly reports「,統計了 2019 年裏 stackoverflow 網站上支持數最高的 20 個問題。問題列表以下(方括號中的兩個數字是其支持數與回答數):python

  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]

不用懷疑,這些內容的支持數和回答數就是那麼少。不過也需注意,它統計的是問題自己的支持數,而不是回答的支持數(儘管回答的支持數也不多)。git

還有一點需注意,這份報告並不是 stackoverflow 網站的官方報告,並且文中也未說明統計口徑與篩選標準,因此咱們姑且一看。web

有些問題可能挺怪的,或者平時不大可能考慮到,好比關於列表的兩個問題:爲何從列表末尾查找時是從 -1 開始?爲何列表的切片容許越界? express

很多回答都挺有專業精神,每每會帶來新的視角和知識信息。好比,關於列表的 -1 索引問題,高票回答中提到了「~」運算符,有這樣的用法:segmentfault

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

讓人眼前一亮!websocket

還有一個問題是:如何優雅地計算 ((x == a and y == b) or (x == b and y == a)) 這個形式的結果?dom

高票回答是這樣:socket

初一看,就像看人變戲法同樣……ide

其它問題和回答就不一一說明了,建議感興趣的同窗按圖索驥,循序漸進,順藤摸瓜,順手牽羊……

連接清單:

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

[1] http://stackoverflow.com/ques...

[2] http://stackoverflow.com/ques...

[3] http://stackoverflow.com/ques...

[4] http://stackoverflow.com/ques...

[5] http://stackoverflow.com/ques...

[6] http://stackoverflow.com/ques...

[7] http://stackoverflow.com/ques...

[8] http://stackoverflow.com/ques...

[9] http://stackoverflow.com/ques...

[10] http://stackoverflow.com/ques...

[11] http://stackoverflow.com/ques...

[12] http://stackoverflow.com/ques...

[13] http://stackoverflow.com/ques...

[14] http://stackoverflow.com/ques...

[15] http://stackoverflow.com/ques...

[16] http://stackoverflow.com/ques...

[17] http://stackoverflow.com/ques...

[18] http://stackoverflow.com/ques...

[19] http://stackoverflow.com/ques...

[20] http://stackoverflow.com/ques...

公衆號【Python貓】, 本號連載優質的系列文章,有喵星哲學貓系列、Python進階系列、好書推薦系列、技術寫做、優質英文推薦與翻譯等等,歡迎關注哦。

相關文章
相關標籤/搜索