TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Spot the bug in this Python code (2023)

8 点作者 dwrodri超过 1 年前

6 条评论

dgan超过 1 年前
Pandas has use cases, but i see it sooo much overused for no reason.<p>People automatically think &quot;csv? I gotta install Pandas!&quot; even if CSV is like 20 lines long. Then follows 15 lines of Pandas DSL that i have to decipher to modify anything<p>I hate it
评论 #39061585 未加载
评论 #38961722 未加载
aidos超过 1 年前
The Python interpreter as acting totally sanely.<p>The author is asking it to loop over a list (or any iterable) and destructure each of the <i>elements</i>. But is then providing a a list containing some strings, none of which can be destructured.<p>Reducing to just the second part of the loop:<p><pre><code> [(x, z) for x, _, z, *_ in [&quot;0x2d41854&quot;, &quot;3&quot;, &quot;0x80001a14&quot;, &quot;(0xbffd)&quot;]] </code></pre> IE in non-list-comprehension form:<p><pre><code> for x, _, z, *_ in [&quot;0x2d41854&quot;, &quot;3&quot;, &quot;0x80001a14&quot;, &quot;(0xbffd)&quot;]: </code></pre> IE, the first element is expanded as:<p><pre><code> x, _, z, *_ = &quot;0x2d41854&quot; </code></pre> Which is clearly nonsensical.
stop50超过 1 年前
Is an generator already too much overhead? Just a small function with an double for loop that yields the data. Easier readable and also bugfree.
alextingle超过 1 年前
If you need to explain how your clever clever Python code works, you&#x27;re doing it wrong.
评论 #39061822 未加载
评论 #38962230 未加载
jethkl超过 1 年前
the bug is the diy csv loader. use instead the csv module or its equivalent. My experience parsing csv&#x27;s (how hard can it be?) often end with nested lists of iterators, complex logic to deal with edge cases, and other things that fail on painful-to-diagnose corner cases - exactly like what the author describes.
bombela超过 1 年前
I found the mistake obvious, but I have some experience with Python.<p>The use of the `for ... in [...]` to destructure the list is quite clever.<p>I would have simply indexed the list.
评论 #38961951 未加载