Catch up on stories from the past week (and beyond) at the Slashdot story archive

 



Forgot your password?
typodupeerror
×

Comment Re:Write-only code. (Score 1) 757

That is something that would be a nifty construct. About the closest I can think of off the top of my head is using a nested generator expression

borbs = [b for b in (compute(orn) for orn in orns) if b > 12]

Which isn't too awkward IMO, it's pretty clear there's two stages: a map and then a filter, and it's more readable than e.g.

borbs = list(filter(lambda b: b > 12, map(compute, orns)))

Comment Re:Write-only code. (Score 1) 757

It depends :)

If compute() is a "heavy" function, then the plain loop is the best, although I'd probably use the

borbs = [b for b in map(compute, orns) if b > 12]

construction LoneTech posted earlier.

If it's a small function in a throwaway script then probably just

borbs = [compute(orn) for orn in orns if compute(orn) > 12]

as you posted.

How about something like

from itertools import dropwhile

def compute(l):
    for i in l:
        yield i * 2

borbs = list(dropwhile(lambda b: b <= 12, compute(orns)))

:D

Comment Re:Write-only code. (Score 1) 757

All of what you stated is convention, documentation and community-agreed definition of Pythonic.

My point was that it's not just the community of people using Python, but that it's also part of the community of people who design Python, and has been from the start. The latter feeds into the former, and then vice versa, and without both sides you end up with at best where JavaScript is today - intense focus on making code better, but every single avenue has multiple options and you end up with a bewildering array of choices.

Comment Re:Write-only code. (Score 4, Interesting) 757

It's both. Type import this from the interpreter, and you'll get this:

The Zen of Python, by Tim Peters

Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!

While it doesn't always manage it, if you read the discussions and PEPs relating to the language's design it's clear that the idea of a "Pythonic" way of doing things is one of the top considerations.

Comment Re:So basically (Score 1) 445

Why would you assume that it will go any differently in 2015 than it did in 2005, 2006 and 2011? The Republicans came out against this bill with accusations that it would help ISIS and risk another 9/11, and when the time for renewal is up in May (not January as I said), they will be in control of both houses and looking towards the primaries and the election after that - they're not going to let it expire

I don't see any chance that it won't be renewed. I'm sure there will be lots of drama, name-calling and stirring speeches, but in the end, little or no substantive changes to the act itself, and it will be 2020 before all this comes up again.

Comment Re:Where's the schema (DTD/XML Schema/Relax NG)? (Score 1) 125

But it's easier to parse HTML5 than it was any previous version of HTML, as there is now an actual specification which details the process exactly rather than relying on each browser's interpretation. It can't be that difficult given the number of working parsers and validators out there for HTML5.

Plus, HTML5 can already be written using XML syntax, aka XHTML5. And searching for xhtml5.xsd or xhtml5.rng gave me plenty of links to schemas for validating XML-syntax HTML5.

If you need to store validated documents, then you shouldn't be storing them in HTML format! Store them as XML documents with well-defined schemas (Relax NG of course!), and then use XSLT or possibly XQuery to turn them into HTML fragments for display.

Submission + - Survive (and Party) Like It's 1920! (survivorlibrary.com)

TheRealHocusLocus writes: The Survivor Library is gathering essential knowledge that would be necessary to jump-start modern civilization, should it fail past the point where a simple 'reboot' is not possible. Much of it (but not all) dates to the late 1800s and early 1900s: quaint, but we know these things work because they did work. Does modern civilization offer a real backup-pan? Not a priority. Wait for help. In 1978 James Burke said our modern world has become a trap, and whether it springs shut or not all true roads to survival lead to the plow. Could you make one, use one? Sure, even a steam engine to pull it. I rescued my copy of Henley's Formulas from a dumpster outside a library. This is happening all over. It makes my blood run cold.

Think of it Survivor Library as a trove of survival skills, a "100 year civilization checkpoint backup" that fits on a hard drive. If one individual from every family becomes a Librarian, gathering precious things with the means to read them, there may be many candles in the darkness. You might even ensure survival. Browse at will, but if acquisition is the goal, someone has kindly made a torrent snapshot as of 14-Oct-2014 available to all Ferengis. If the worst happens we'll just party like it's 1920. See you there.

Comment Re:OT:Mod points (Score 1) 553

You won't get them if your karma is too high or too low, or if you browse /. too often or too infrequently. Possibly also if you post often enough you won't get them either, there are a few different factors. I went years getting none, now I get 5 points every five or six days, and occasionally 15 points instead.

Comment Re:I've been impressed with IE lately (Score 1) 122

Go to Settings and Phone Update is about halfway down - you can check for any missing updates to the OS there. I think you need to be on Wi-Fi or plugged into the PC to work though.

Also below that in Settings the About page should be able to tell you what versions you have for the OS, firmware etc. I'm currently on OS v8.10.12393.890 :)

Slashdot Top Deals

Understanding is always the understanding of a smaller problem in relation to a bigger problem. -- P.D. Ouspensky

Working...