|
Avenging Dentist posted:Or just, you know, use a set.
|
# ? Aug 29, 2009 21:36 |
|
|
# ? Jun 12, 2024 03:15 |
|
UnNethertrash posted:If you have a list that you know is sorted, is there a built in way to efficiently search the list? The primes are more or less evenly distributed so you should be able to do better than binary search with some guessing and arithmetic. Actually a million isn't all that big, just make a list of True and False and blammo you have an O(1) algorithm.
|
# ? Aug 29, 2009 22:53 |
|
Avenging Dentist posted:Or just, you know, use a set. What do you mean? Set is unordered, it only prevents repeats of any item. Does it have a built it binary search or something? Ninja edit: I think I figured it out, if it's in the set it's prime. Is this fast? Fritz: Do you mean setting it up so you just basically... code:
|
# ? Aug 30, 2009 00:56 |
|
UnNethertrash posted:What do you mean? Set is unordered, it only prevents repeats of any item. Does it have a built it binary search or something? "Unordered" doesn't mean what you think it means. I'm pretty sure Python sets use a hash table.
|
# ? Aug 30, 2009 01:18 |
|
Avenging Dentist posted:"Unordered" doesn't mean what you think it means. I'm pretty sure Python sets use a hash table. It does, it happens to be a very very fast hashset to boot. On simple numeric keyed hashsets I can often benchmark python as being faster than std::tr1::unoreded_set.
|
# ? Aug 30, 2009 01:44 |
|
king_kilr posted:It does, it happens to be a very very fast hashset to boot. On simple numeric keyed hashsets I can often benchmark python as being faster than std::tr1::unoreded_set. This is a stupid benchmark to make since there are already several completely separate implementations of unordered_set (or rather, it's a stupid assertion to make from a single benchmark).
|
# ? Aug 30, 2009 01:51 |
|
UnNethertrash posted:What do you mean? Set is unordered, it only prevents repeats of any item. Does it have a built it binary search or something? Read the bold part, and think about what it means regarding searches for set membership.
|
# ? Aug 30, 2009 01:56 |
|
...
maskenfreiheit fucked around with this message at 03:51 on Sep 29, 2010 |
# ? Aug 30, 2009 05:13 |
|
king_kilr posted:On simple numeric keyed hashsets I can often benchmark python as being faster than std::tr1::unoreded_set. For integers hash(n) = n in the python dictionary implementation* quote:Major subtleties ahead: Most hash schemes depend on having a "good" hash * Except hash(-1) = -2
|
# ? Aug 30, 2009 13:50 |
|
GregNorc posted:So I'm looking to learn python. The links in the op are still good. Dive Into Python (free online) and others are great resources.
|
# ? Aug 30, 2009 14:40 |
|
tef posted:For integers hash(n) = n in the python dictionary implementation* That's all true, however the speed of a hashtable implementation involves more than just the cost to hash something.
|
# ? Aug 30, 2009 17:19 |
|
It's not the only thing I just thought it was interesting
|
# ? Aug 30, 2009 20:51 |
|
tef posted:It's not the only thing I just thought it was interesting Actually anything that hashes to -1 returns -2 for it's hash: code:
|
# ? Aug 30, 2009 21:28 |
|
Edit: doublepost
maskenfreiheit fucked around with this message at 01:13 on Mar 13, 2017 |
# ? Aug 30, 2009 23:05 |
|
I'd just do:code:
Or with nice whitespace: code:
|
# ? Aug 30, 2009 23:20 |
|
king_kilr posted:I'd just do: code:
|
# ? Aug 31, 2009 00:17 |
|
GregNorc posted:Ok, quick question: can I make a list of lists in python? Use nested for loops. There is no reason to use a while loop since you are basically iterating through fixed sets.
|
# ? Aug 31, 2009 01:19 |
|
Soviet Space Dog posted:Use nested for loops. There is no reason to use a while loop since you are basically iterating through fixed sets. Or even better (and more pythonic), use the list comprehension ATLBeer posted above
|
# ? Aug 31, 2009 03:21 |
|
Does anyone know if PIL supports the creation of animated GIFs? I'm creating a small command line utility for a buddy that will input a small image, make it a two-frame animated GIF with one frame that has a single pixel with a slight coloration difference for import into Windows Live Messenger as an emoticon (the point of doing so prevents WLM from distorting the emoticon by automatically resizing it). If PIL isn't the best imaging library for this sorta thing, any recommendations for something better would be great.
|
# ? Sep 1, 2009 01:14 |
|
root beer posted:Does anyone know if PIL supports the creation of animated GIFs? A bit of searching led me to http://sites.google.com/site/almarklein/files-1/images2gif.py , which should show you what you want.
|
# ? Sep 1, 2009 01:17 |
|
Scaevolus posted:A bit of searching led me to http://sites.google.com/site/almarklein/files-1/images2gif.py , which should show you what you want. Thanks!
|
# ? Sep 1, 2009 01:30 |
|
I'm having a bit of trouble daemonizing a script. I found a couple of examples online, and am using this one because I felt like I understood it: http://www.enterpriseitplanet.com/networking/features/article.php/11315_3786386_1 code:
Redirecting stdout to a file within my main script (when NOT daemonized) works fine. For example: code:
Commenting out the entire block in the daemon script after "# The process is now daemonized" does not seem to affect whether or not stdout redirection is working within my main script when daemonized. The script otherwise functions normally. I'm really confused. I know nothing about how stdout and stderr work with filedescriptors, or the proper procedure for dealing with them. If it matters, this is on CentOS 5.3. ShizCakes fucked around with this message at 19:51 on Sep 1, 2009 |
# ? Sep 1, 2009 19:49 |
|
ShizCakes posted:I'm having a bit of trouble daemonizing a script. After waiting a long time, I noticed that it was outputting things in 4K blocks. That lead me to suspect that there was buffering occuring of sys.stdout - and there was! Not sure why it was happening when daemonized but seemingly not when not daemonized, but the answer to my woes was found here: http://stackoverflow.com/questions/107705/python-output-buffering
|
# ? Sep 1, 2009 20:27 |
|
ShizCakes posted:After waiting a long time, I noticed that it was outputting things in 4K blocks. That lead me to suspect that there was buffering occuring of sys.stdout - and there was! Yup, stdout buffering is one of those things you inevitably run into and then (hopefully) never forget about afterwards. I sort of wish it was highlighted more in tutorials, aside from the "learn to program!" tutorials where it would be a bit much. In these situations I often find myself just making a stupid little subroutine that does the flushing; outright replacing sys.stdout like in that SO thread is a more complete solution, at the expense of loving around with internals (i.e. and possibly surprising coders who come after you and aren't expecting it.) It's sometimes necessary, though
|
# ? Sep 1, 2009 20:36 |
|
code:
Any pointers? (Also just checked out latest version from jinja's mercurial and get the same error) eh... oh well: python setup.py --without-speedups install that works OK... This is now a reoccurring problem. Seems like Snow Leopard and distutils might not get along Fabric just failed in the exact same way (with installing pycrypto) ATLbeer fucked around with this message at 22:31 on Sep 2, 2009 |
# ? Sep 2, 2009 22:13 |
|
You need to reinstall XCode after installing Snow Leopard. EDIT: upon actually reading your code, maybe not. it looks like you have gcc, but it just isn't working. Still, if you haven't, do so.
|
# ? Sep 2, 2009 23:16 |
|
Sailor_Spoon posted:You need to reinstall XCode after installing Snow Leopard. Yeah.... I reinstalled XCode, then reinstalled it w/ 10.4 support... Dunno why Neither made a difference
|
# ? Sep 2, 2009 23:47 |
|
ATLbeer posted:Hmmm... I had jinja2 installed and working on Leopard but, after my Snow Leopard upgrade it didn't exist and now I can't seem to build it. I haven't used Snow Leopard yet, but I'm going to guess that it has a 64-bit build of Python. Try this before installing: code:
|
# ? Sep 3, 2009 00:43 |
|
ATLbeer posted:Yeah.... I reinstalled XCode, then reinstalled it w/ 10.4 support... Dunno why You're using the default python2.6.1 installation, right? Not something left over from installing python2.6 from python.org? I had no problems pulling in Jinja2, which is a dep of sphinx
|
# ? Sep 3, 2009 01:50 |
|
m0nk3yz posted:You're using the default python2.6.1 installation, right? Not something left over from installing python2.6 from python.org? I had no problems pulling in Jinja2, which is a dep of sphinx You just made me double check... My work Mac I have 2.5 installed and on my home laptop I have 2.6.1 Both fail in the exact same way. code:
|
# ? Sep 3, 2009 03:51 |
|
Xenos posted:I haven't used Snow Leopard yet, but I'm going to guess that it has a 64-bit build of Python. Try this before installing: code:
ATLbeer fucked around with this message at 04:00 on Sep 3, 2009 |
# ? Sep 3, 2009 03:53 |
|
ATLbeer posted:Are you trying to install as sudo? If so, pass it through like this: code:
|
# ? Sep 3, 2009 04:11 |
|
Xenos posted:Are you trying to install as sudo? If so, pass it through like this: http://pastebin.com/f6c96dcfa And I do have XCode installed, latest version I believe [3.2 (1610)]
|
# ? Sep 3, 2009 04:32 |
|
ATLbeer posted:http://pastebin.com/f6c96dcfa I can confirm that on Snow Leopard, fresh install - no ARCHFLAGS set and the xcode that ships with leopard, it installs OK: code:
|
# ? Sep 3, 2009 14:21 |
|
m0nk3yz posted:I can confirm that on Snow Leopard, fresh install - no ARCHFLAGS set and the xcode that ships with leopard, it installs OK: /Library/Frameworks/Python.framework/Versions/Current/bin/python $ export | grep MACOSX Is this this the default config? The follow up I guess is how do I regress to the standard install without blowing away my install ATLbeer fucked around with this message at 16:37 on Sep 3, 2009 |
# ? Sep 3, 2009 16:10 |
|
ATLbeer posted:$ which python code:
In order to reset it, I think all you need to do is remove any custom $PATH settings and make sure you're pulling in /usr/bin python. In fact - try that with the Jinja2 install - "/usr/bin/python setup.py install"
|
# ? Sep 3, 2009 19:36 |
|
Hi, beginner coder here so any help would be much appreciated for Python 3.1.1: #A simple program. print ("Mary had a little lamb,") print ("it's fleece was white as snow;") print ("and everywhere that Mary went") print ("her lamb was sure to go.") Output: Mary had a little lamb, it's fleece was white as snow; and everywhere that Mary went her lamb was sure to go. ------------ In the above, how do I recode so the last 2 lines run into each other without a line break? I remember it involving '\' somehow, but I can't get it to work with the 'print' function. Also, is there any important difference between using ' and " to enclose strings? duneriver fucked around with this message at 10:38 on Sep 4, 2009 |
# ? Sep 4, 2009 09:25 |
|
duneriver posted:In the above, how do I recode so the last 2 lines run into each other without a line break? I remember it involving '\' somehow, but I can't get it to work with the 'print' function. print("string", end="") duneriver posted:Also, is there any important difference between using ' and " to enclose strings? ' lets you embed " in them and " lets you embed ' in them!
|
# ? Sep 4, 2009 12:41 |
|
Thank you!
|
# ? Sep 6, 2009 17:25 |
|
|
# ? Jun 12, 2024 03:15 |
|
I made some stupid decorators:code:
|
# ? Sep 6, 2009 17:39 |