TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Spot the bug in this Python code (2023)

2 pointsby dwrodrialmost 2 years ago

2 comments

t-vialmost 2 years ago
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 未加载
simonblackalmost 2 years ago
<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 未加载