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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

Spot the bug in this Python code (2023)

2 点作者 dwrodri将近 2 年前

2 条评论

t-vi将近 2 年前
The logic error seems to be that you have the second for loop where you only want to destructure the splitted line into a tuple. Now writing that decomposition as a for loop over a one-element list (as in the corrected code) works, but seems &quot;hmhm&quot;. In other words, the misunderstanding here is that you want a chain of generators, not a &quot;nested for loop&quot;-generator.<p>A more proper solution could be to chain the generator expressions: with<p><pre><code> lines = [&quot;a,b&quot;, &quot;c,d&quot;] </code></pre> you could do<p><pre><code> ((a,b) for a, b in (l.split(&#x27;,&#x27;) for l in lines))</code></pre>
评论 #36988900 未加载
simonblack将近 2 年前
<i>(0x00800513),x10,0x8</i><p>Well, I&#x27;m not a Python guy, but I saw something that would have been a bug. As numbers, the line above&#x27;s variables would evaluate to<p><pre><code> 0x00800513 0x0000 0x8 </code></pre> In a language like C, in a compilation, that &#x27;x10&#x27; would throw up a &#x27;variable not declared&#x27; error. As data, it would most likely evaluate as above to zero (depending on the data-handling code).
评论 #36871379 未加载