« first day (1629 days earlier)      last day (3317 days later) » 

5:00 PM
Would you lose three rep for that?
 
DSM
@matsjoyce: heh. Usually up, I'll admit. It's not even that I want to get extra points -- maybe being able to redistribute points from answers which are right but are too highly voted to answers which deserve more points than they've got would suffice. Probably there's no way to make it work, but still.
 
@matsjoyce In what situation could you see someone down-voting their own answer? :P
 
DSM
People ragequit from time to time. I could imagine ragedving.
 
@DonkeyKong They want sympathy upvotes? Could work.
 
well to be honest high vote answers are usually very simple ... complex answers do not have enough people who have that problem or understand the answer
the top voted answer is probably something like
" ".join(a_list)
 
5:03 PM
 
@JoranBeasley very true
 
Top one's quite long.
 
@matsjoyce I agree actually. Downvotes own answer, then comments on it Why the downvote? This is correct!, earns multiple upvotes.
 
But in Python, we can compile a small book with e-satis' answers
 
DSM
@DonkeyKong: ooh, that's clever.
 
5:04 PM
@DonkeyKong And then un-down votes.
 
DSM
I'm totally not thinking of creating a sockpuppet account solely to downvote for those reasons. Not at all.
 
1417
A: Best way to check if a list is empty

Patrickif not a: print "List is empty" Using the implicit booleanness of the empty list is quite pythonic.

 
903
A: How do I randomly select an item from a list using Python?

Pฤ“teris Cauneimport random foo = ['a', 'b', 'c', 'd', 'e'] print(random.choice(foo))

 
@DSM Guilty of "serial self-downvoting" :P
 
That's 14258 (14.3k) rep for 3 lines.
 
5:06 PM
lol
case in point :P
 
806
A: Merge two lists in Python?

Daniel GPython makes this ridiculously easy. mergedlist = listone + listtwo

 
1600
A: Does Python have a ternary conditional operator?

Vinko VrsalovicYes, it was added in version 2.5. The syntax is: a if test else b First test is evaluated, then either a or b is returned based on the Boolean value of test; if test evaluates to True a is returned, else b is returned. For example: >>> 'true' if True else 'false' 'true' >>> 'true' if False ...

 
WTF
721
A: Installing pip on Mac OS X

Scott David TeslerAll you need to do is sudo easy_install pip

 
DSM
Just think of all the rep we'll get when SO starts getting KevinScript questions!
 
That one's 15.2k for a if test else b
 
5:08 PM
721 upvotes for All you need to do is sudo easy_install pip o.O
 
If you were to invent a language and get people to use it with the sole intent that you get lots of SO points, but the language turns out to be useful, you'll get the most awesome posts on meta about it.
 
@thefourtheye: if you are not using Skype, what chat methods do you use outside of this chat room? :-P
 
DSM
To be fair, I just hit 100 for numpoints=1 the other day.
 
yeah i know my top answers are stupidly simple
23
A: loop backwards using django template

Joran Beasleydirectly from the page you linked You can loop over a list in reverse by using {% for obj in list reversed %}.

there is my most upvoted one ...
 
@MartijnPieters Nothing :) Let me check skype.
 
DSM
5:10 PM
But I guess that's the point: it'd be nice to move some of that unearned rep to answers where it really belongs. I'd even be willing to pay a penalty for it.
 
why does python tags doesn't have snake beside the tag while go has gopher????
 
because yes
 
@ChillarAnand because the Python Software Foundation doesn't see a need to sponsor the tag.
 
@ChillarAnand Aye! We demand equality!
 
While Google does see a need to fork out loads of money to Stack Exchange to sponsor the tag.
 
DSM
5:13 PM
What do they get in exchange for the money? I mean, people were going to ask and answer go questions regardless, no?
 
@DSM The icon means everything.
Rhubard(all)
 
DSM
Rhubards sing songs of farewell.
 
We should have a song.
 
๐…œ ๐… ๐…—๐…ฅ ๐…˜๐…ฅ ๐…˜๐…ฅ๐…ฎ ๐…˜๐…ฅ๐…ฏ ๐…˜๐…ฅ๐…ฐ ๐…˜๐…ฅ๐…ฑ ๐…˜๐…ฅ๐…ฒ
 
5:23 PM
It's just the council chanting PEP 20 while someone hums "ommm ommm" in the background
 
Wish I could have hammered this post, but the common questions database only had a near-match :-(
 
@davidism lol, we should do Google Hangout and try that once :D
 
DSM
@Kevin: I remembered that question too, mostly because I remember my description of what I mean by "clever" there. Using that pattern you can answer the OP's question in two reasonably-clean lines.
If we want to do something practical, I still like my idea of each of us writing out lines from the Zen.
 
im going for my simple answers
0
Q: can't install urllib3 on raspberry pi for python3.4

Yábir GarciaI built python3.4 and created an alias using: echo alias py="/opt/python3.4/bin/python3.4" >> .bashrc and I work ok with it but when I try to use urllib3 it says it is not istalled, so I tried sudo pip install urllib3 but when it has finished you can not use it with python3.4, so I tried ...

 
Okay, have to sleep now... Sigh... I wish I recover faster...
rbrb Guys
 
5:34 PM
@Kevin Wow. Some of those answers are insanely complex. That's about five lines of Ruby, without trying to make it compact. It's gotta be about the same in Python.
 
Five sounds about right, if Jon's recipe isn't disqualified as "complex"
I'd probably do it like
result = []
for group in [#insert jon's recipe here]:
    if len(group) == 1:
        result.append(str(group[0]))
    else:
        result.append("{}-{}".format(group[0], group[-1]))
 
DSM
I tend to write grouped = complex_recipe/for group in grouped: rather than for group in complex_recipe. For some reason I don't like for lines with much logic in them.
 
And of course you can go crazy with compactness by doing result = [str(group[0]) if len(group_ == 1 else "{}-{}".format(group[0], group[-1]) for group in [#insert jon's recipe here]]
@DSM I see where you're coming from. I try to keep generator expressions outside of my for conditions. Ex. for x in [y **2 for y in range(10)] looks weird. Too many fors.
 
this didn't work in this instance โ€“  YK2 19 mins ago

@YK2 Did your computer explode? Did monkeys fly out of the screen? Did the house melt? What does "This didn't work" mean? โ€“  Adam Smith 18 mins ago

the code that you suggested โ€“  YK2 14 mins ago

@YK2 You need to be more specific than that. What did not work exactly? โ€“  ILostMySpoon 11 mins ago

but thanks for your help anyway โ€“  YK2 6 mins ago
sigh
 
I strongly suspect his true error is "it didn't work when I did zip_command = "zip -r {0} {1}".format(target, ' '.join(source)) later in the tutorial"
Changing source to a not-list actually breaks functionality. Not that anyone could guess that unless they knew what site he was reading from.
 
5:47 PM
I wasn't about to dig through the tutorial he's copying verbatim in order to help him fix an error he doesn't understand
especially when his comments are so useless.
"doesn't work."
"Why, what happened?"
"the code that you suggested."
"Please be more specific"
"thanks for your help"
 
DSM
Newbies gonna newb. Just shake it off.
 
does the Taylor Swift
 
lol
 
Either the tutorial or the OP is putting the cart before the horse by using join before they know what a list is.
 
@Kevin ooo... list - is that new and coming out in Python 3.5? :p
 
5:53 PM
The list data type is available only to Python Gold (tm) members.
Order now and receive a commemorative tote bag.
 
Umph... I'll hunt around for a discount code first :)
 
I thought I had a handle on this question until they started talking about primitive generators. I don't know what that is, but I'm guessing it's not a fancy name for "integer"
 
DSM
Not quite. :-) I'm not entirely sure why he isn't using one of the built-in discrete_log functions, but I'm about to head off to lunch, so whatever..
 
@BhargavRao, you should mention itemgetter too, so as to satisfy readers that hate lambda.
(re: this question)
 
@Kevin Thanks! Hadn't seen it here
OH! The ugly rep cap has hit me
 
6:08 PM
Guess you'll have to go for accepts now, which are cap-free
 
Yeah
1 accept required
 
@BhargavRao one accept for 10k :p
 
Yeah
That to exact 10000
 
Or go bounty hunting :P
 
I can post like FIzzy
@DonkeyKong Naw. I need exact 15
 
6:11 PM
@BhargavRao How satisfying would it be to surpass that 10k pinnacle with a bounty answer though. Think about it.
 
I wonder if a clever solution exists for this guy's desired behavior of "at least one of both"
 
@DonkeyKong lol Yeah. But it is hell late here! I'll try that for 15k
 
umm... "Leader's debate" on in 49 minutes... might be interesting comedy
 
Are dupes under the ambit of the ten minute rule?
 
@Kevin Just for fun, here's how you might do it in Ruby, abusing the #slice_before function. It's a little bit obtuse, but I wanted an excuse to try out #slice_before:
line_nums = [ 1, 2, 3, 5, 7, 8, 9, 10 ]
last = line_nums.first
ranges = line_nums.slice_before do |e|
  begin
    !last || e != last + 1
  ensure
    last = e
  end
end.map do |a|
  [a.first, a.last].uniq.join("-")
end
p ranges     # => ["1-3", "5", "7-10"]
 
6:18 PM
mm hmm, mm hmm. I know some of these words.
 
polite applause
 
Thanks all
 
nods in acknowledgement
 
Nice
 
6:22 PM
Quick, downvote Rao's stuff.
 
@Kevin For the record, your Python code is, I think, easier to read.
 
Thanks to rep-cap for exact 10000
@QuestionC Nope won't work
 
okay I have a dumb question. Is it possible to efficiently generate a string matching a regular expression without brute force?
 
Yes.
 
You've gotta downvote 18 times
 
6:23 PM
Maybe...
Actually, yes.
 
I vaguely remember something like that from college.
 
It's an interesting question.
 
First, you transmogrify the regex into a nondeterministic finite state machine.
 
I believe it's also been asked a few times on the site...
 
But I'm pretty sure that if you can generate the state machine for a regex, then all you need to do is find a path to an end and you have the string.
 
6:25 PM
Then, starting at the start node, you traverse the graph, adding letters to your output as you move across edges, until you come upon the terminal node.
So, yeah. What QuestionC said.
 
What Kevin said.
QC gets -10 points on the test for an incomplete answer.
 
Lookbehind and lookahead make it a little more interesting.
 
Those also aren't regular expressions. They're extended regular expressions.
 
@Kevin that was my thought for doing it by hand, not sure how to do it by a computer. I want to ask this on SO now
 
6:27 PM
Which I guess is still a misnomer since "regular" is still in there.
 
rbrb all! Good night
 
@BhargavRao rbrb! congrats again!
 
That's a really fun question, it'd be good before it got closed due to "Show your work".
 
@corvid does this help
3
Q: Efficient algorithm for string matching with a very large pattern set

lquerelI'm looking for an efficient algorithm able to find all patterns that match a specific string. The pattern set can be very large (more than 100,000) and dynamic (patterns added or removed at anytime). Patterns are not necessarily standard regexp, they can be a subset of regexp or something simila...

 
I've done it before for bare-minimum "parens and kleene star and pipe" regexes. Alas, I don't have the code.
 
6:27 PM
@JonClements Thanks puppy! It would not have been possible without all your help
 
@JGreenwell sorta, what I am trying to do is take a schema, and if it has a RegExp constraint, generate a somewhat random string to be accepted
 
it has a good discussion on that. Also, I was actually just looking that up for a school project @davidism :)
@covid It's not directly related but I was reading the discussion for my project and it gave me a few ideas - so wondered if it would help you as well
 
6:40 PM
Needs reproducing code
 
6:58 PM
Is there a level of downvotes that causes a post to be deleted or closed. Before the 30 day mark, I know the rule on no answer + negative score, but can't find if their is a downvote cap on any day.
 
Heavily downvoted stuff shows up on the 10k+ tools page. I don't there's a cutoff.
 
@JGreenwell also, once a question receives a certain number of downvotes, 10K+ (or maybe 20K+, I forget) users see a delete option along with close, flag, etc., making deletion of extremely poor-quality questions that much easier.
 
@davidism ah, thanks. Saw a post, clearly off-topic and probably spam, but it had so many downvotes by then I wondered if it would be better to flag or just wait. Seems waiting as its gone now.
@MattDMo thanks as well
 
Sorry, @JonClements, but every time I hear a Brit say "*amusing*" I think of that line from The Life of Brian:

Do you find it amusing when I say ... Biggus ... Dickus?
 
7:07 PM
lol
 
-2
Q: Skip all lines in try if one line fails

HarilaI need line 3 to run before 5. But if line 4 fails I dont wont to run line 3. Is it a way to do that? print "Print ME" try: print "1)Only print if try go through" print 1/0 print "2)Only print if try go through" except: print "Fail"

 
This debate looks pretty similar to a primary debate in the US. I was hoping for people throwing shoes.
 
Hopefully it'll pick up when they get a small bit of time to rip into each other
 
rbrb all
 
rbrb
 
7:13 PM
I want time travel in my code, too.
What I think the OP really needs is to be writing to a buffer, and only output the buffer at the end when everything is hunky dory and decided. But I can't tell for sure from that question.
 
I have similar suspicions. I have politely asked OP to not require us to read his mind.
 
I have politely upvoted your polite comment.
 
I politely nod in polite recognition of your politeness.
 
I have posted stupid comment and received no upvotes.
 
the word "polite" has now reached semantic satiation and I will no longer use it.
 
7:17 PM
@Kevin how courteous :)
 
I believe this got closed too early
 
DSM
Do we really have no one with a January birthday?
 
@vaultah Probably got voted as unclear because a formatting issue caused the second half of his post to go missing. edited and voted to reopen.
 
DSM
Still seems unclear to me. Are we being asked to write a baby C++ parser in Python?
 
Sounds right.
 
7:22 PM
Yeah, but now it's a different kind of unclear. We should vote to reopen and then close it again.
 
It's still pretty incomplete.
 
@Kevin oh wow, didn't know that < has special meaning
 
I'm not sure why markup failed there, actually... Probably something to do with html tags, but I've seen the less-than symbol work just fine before.
Maybe it's specifically <b that makes the engine think a tag is coming?
 
DSM
That's possible.
 
Yeah, I'm wrong again :'(
 
7:25 PM
That question needs more TLC before it can be reopened.
 
Playing around with the editor, I see that adding a space between < and b also fixes it.
@WayneConrad Yeah, I don't have much hope though since OP didn't even hang around long enough to make sure his post actually displayed right.
 
DSM
Just wait until he comes back and the question is deleted and his account is closed and everything!*
[*may not occur]
 
Does your account get closed if your first question gets closed and deleted?
 
DSM
Speaking of closed accounts, the account of the kid I was wondering about a few days ago has been shut down.
 
@WayneConrad No, I think you get more leeway than that.
 
DSM
7:29 PM
@WayneConrad: I don't think so, I think you have to have at least N failed questions for some N.
 
Or maybe I'm thinking specifically of self-deleted posts. You can have a handful of those before you get into trouble.
 
"Not enough words so :

Lorem ipsum dolor sit amet, consectetur ..."
:d
 
DSM
Yeah, I saw that. Sometimes they don't even pretend to try.
Plus his "description" is wrong; his youGot variable has nothing to do with it.
 
DSM
@Wayne: does this happen on your side of the aisle as well?
 
7:39 PM
I'd say it's about the same, just more concrete now.
He still wants the "don't let X thing happen if Y thing fails" functionality
 
@DSM Probably. I don't pay too much attention to the queues lately (except when I'm hanging out here).
 
DSM
Okay, opinion: this guy should be using & instead of &&. Answer, or close as typo?
 
I'd vtc
 
@Kevin Kinda sorta, but the Q has already got a well-meaning attempt at an answer that now makes no sense whatsoever.
 
@DSM mmmmm, answer.
 
DSM
7:43 PM
One yea, one nay. You people are no help whatsoever.
 
:D
 
:-p
I like to save "typo" for posts where the OP thought the right code but wrote the wrong code. If he actually thinks that & is correct, then answering is fine.
 
Ugh, nvm
 
I guess my reasoning only works if you can effectively guess what the OP is thinking.
"Psychic debugging" in its most literal sense.
 
Whenever someone says "Sorry, but...", I'm pretty sure that what they really mean is "I'm not sorry, and..."
Ditto for "Honestly," "I've got to tell you," etc.
 
7:51 PM
hello, everybody
 
Howdy!
 
Hello @Garrett
 
This is my first adventure into the Python room. I usually hang out in the javascript room
Is it just as weird over here?
 
Yes.
 
Brilliant
 
DSM
7:53 PM
More vegetable-based, for one thing. Kevin's a bit of an exception.
 
Observe sopython.com/salad and sopython.com/chatroom for a quick overview of room culture.
 
To the docs!
 
Going to bed, rhubarb guys
 
@WayneConrad Yep, this is true for me.
 
DSM
I'm still a little miffed no one liked my "rhubard" line from before.
 
7:55 PM
I add it to my messages when I think my tone is too demanding. "I can't diagnose your problem without an MCVE" is a bit more harsh than "sorry, but I can't diagnose [etc]"
 
DSM
When I want to make sure the tone is right, I say things like ":-( Unfortunately I can't help until you X" or something. I think it comes across more like I'm sad.
 
I am a little sorry, I suppose. Sorry I can't score some quick rep off of a well-presented post :-p
On a semi-related topic, I have identified three problems in this code, but none that would cause an OSError.
 
Not sure if it's worth making a post that only fixes 75% of OP's problems.
"This is great and all, but I'm still stuck in the while loop", says my imaginary version of OP. You got me there.
It's probably a current working directory issue, which is always a bit hard to wheedle out
 
DSM
Heh, the Julian accepted my answer.
 
8:02 PM
@DSM I value your contributions. Just, sometimes in an undetectable way.
When you're looking up at the moon, just remember that I'm out there somewhere looking at the same moon. And also going "heh" to myself at your posts.
 
mongodb III is so much better than previous versions
 
Name five reasons why.
 
How do you deal with questions where the answer is basically "Yes"?
 
I usually just skip it unless I can think of a really eloquent way to say "yes" that gets past the minimum length requirement.
 
Hmmm. I'd be tempted to explore the complications... data arrives in burst, you may want a low-pass digital filter to keep it from being too jiggly, etc... but I don't know if I'd go through the trouble.
 
DSM
8:17 PM
I've seen people use the language-specification comments to post just a "Yes" or "No". Usually that gets a lot of upvotes from people who haven't seen the trick before.
 
That question in particular, you could talk about sliding averages and stuff.
 
Get enough data scientists in here and I bet they could argue indefinitely about the best approach :-)
 
DSM
Soon Fizzy will be able to tell us!
 
Oh, is Fizzy a pupal data scientist?
 
DSM
8:20 PM
I should write a query for questions with no answers, exactly one comment, and that comment is highly upvoted.
 
Yea, it feels like you could post a really rich general-purpose answer about measuring download progress.
 
DSM
@Wayne: if all goes well soon he will emerge from his chrysalis and spread his multicoloured wings.
Not a bad outcome for a physicist with an interest in data and programming.
 
Oh, physicists butterflies are pretty. You never know what the heck they're saying, though.
 
DSM
I'm more worried about the damage their wing-flapping might cause on the other side of the world! Tsunamis and whatnot.
 
If you can't measure it, it doesn't exist. Unless you're a string theorist.
 
DSM
8:24 PM
Hey, now. No one ever promised that stringy behaviour would be easy to experimentally access. :-)
 
Let me know when we discover the Universe's administrator prompt. I want to try out noclip.
 
:D
Be careful with that 'rm' command...
 
Air
pycharm stahp, I do not want to convert my __repr__ method to a property
 
DSM
Are you suuure?
 
Could someone help me with something? I'm working on Project Euler #31, and I seem to be missing a case, but I'm not sure what it is
It's far from perfect, I know
My method is to add subsequent terms to a list, then when it reaches the desired total, remove everything back to the next term that could be broken down, and repeat from there
 
8:38 PM
my event map doesn't work :\
 
DSM
Neither amounts nor getNext seem to be defined.
 
Can you post the whole code?
 
Oh whoops, sorry
 
Or is it crazy huge? (In which case... rewrite)
 
I had 3 different functions I was working on and then scrapping, and forgot I added some convenience globals
Hm, defining amounts differently inside and outside of getNext was probably a bad idea
and there's probably a more elegant way to replace getNext with like, 3 characters.
 
I can barely even understand my solution to #31 (and all of my code is beautiful and pure). I don't think anyone can easily identify problems in your code. It's just a weird double-loopy problem that is hard to reason about.

Have you tried printing `li` every time you perform `total += 1`? That should give some info.
 
@QuestionC Hehe, well that's some consolation at least. I have been adding extensive print statements that I removed from the pastebin for brevity (and because most of them probably aren't actually all that helpful)
I think I might've narrowed down the problem though
It seems I'm not properly adding the final term in
So when it's something like 10 that can get broken down further, it's not and just removes the last two terms instead of just that one that could get reduced more
and continuing from there
 
bah, the template inheritance here is bad
 
DSM
I get 73682. Is that right?
 
@DSM Yes! :D
 
9:00 PM
I seem to recall that the making change problem will yield nicely to a recursive solution.
 
Now I just have to figure out how I got 73681...
 
DSM
I got 6xxxx or something with your code, I think.
 
John
What happens when [li] is [200]?
 
@DSM Oh yes, I changed it since then :3
@QuestionC aaaand that would be it.
200 doesn't get added.
Yay! It works!
Thanks guys :D
 
Helping with Project Euler problems makes me feel dirty.
 
9:02 PM
@QuestionC It's not like you gave me the answer
I've literally spent weeks on this problem
and came within 1 of the correct answer with my own code
 
DSM
If you're spending weeks I think you're going about debugging your answers the wrong way. Brute-forcing a smaller example to see exactly what you're missing is often a handy approach.
 
and then I was only off by one because I forgot to add an exception I added in the last version :3
@DSM Yes, you're right
I should do that
@QuestionC I know what you mean, though. Having to ask makes me sad :(
 
DSM
Rhubarb for all!
 
consults dictionary
Oh, alright, goodbye!
 
I tend to just let the computer do the work on those kinds of problems. [combo for n in range(TARGET//biggest_coin_val, TARGET//smallest_coin_val) for combo in itertools.combinations_with_replacement(coin_values, n) if sum(combo)==TARGET] then go take lunch while it works it out.
 
9:15 PM
I'll bet the correct answer is not 56858031775663947136658820176594969337030274091
That's what my oh-so-clever recursive solution came up with.
 
@AdamSmith Hopefully one day I'll reach the point where that kind of solution actually occurs to me
I really should study recursion more
I feel like that question could've been much simpler if I'd had a better grasp on that
 
@John I'm awful with recursion. That code I wrote literally enumerates every possible combination of coins (with replacement), then checks after the fact to see if they HAPPEN to sum up to 2 pounds.
I'm not sure if there's a worse way to get the answer
but it's faster for me to know that solution, type it in, and get it running than for me to try to figure out how to implement a recursive solution that finds it quickly
so in terms of raw time for one run -- mine is quicker (for me!)
 
0
Q: How wo solve: ValueError: classes should have valid labels that are in y with scikit-learn?

john doeI have been using scikit learn in a text classification task. I am adding features in order to see what happens when I remove or add some sentences. For this I am creating several datasets. When I add some new feature my baseline dataset I got: Traceback (most recent call last): test.py", line...

 
@AdamSmith See when I try this, whatever terrible code I've thrown together grinds my computer to a halt.
I was just noticing the vast majority of the answers in the answer thread seemed to be based on recursion
 
9:41 PM
@John that code WILL grind my computer to a halt. That's why I take my lunch break after ;)
 
I did not understood you Adam e_e
 
@AdamSmith hehe
 
@johndoe I wasn't responding to you -- I don't know anything about scikit-learn :)
 
9:56 PM
Stupid question: suppose I have a list lst = [2, 3, 4, 5]. What does lst[::-1] even mean? I know what it DOES, and the meaning of just one colon is quite intuitive, IMO. But I have no idea what two colons do.
 
438
Q: Reverse a string in Python

oneselfThere is no built in reverse function in Python's str object. What is the best way of implementing this? If supplying a very concise answer, please elaborate on it's efficiency. Is the str converted to a different object, etc.

that's about reversing a string, @Clarinetist, but the top answer talks about the extended slice syntax that's used there
 
AH, thank you @AdamSmith!
 
in brief: slices are defined as [start_index:stop_index:step_amount]. By leaving start and stop indices empty and defining a step of -1, you're saying to start at the end, step by one element each time, and stop at the beginning
 
10:39 PM
@AdamSmith but thats a silly solution for most denomination sets
99.9999% of the time a greedy solution will yield optimal results
of coarse its usually a trap to demonstrate non-standard denomination sets that break the greedy algorithm
oh nm I see the followup
 
@JoranBeasley Right. The point I was (ham-handedly) making is that for my use case, I don't have to write recursive algorithms often enough to be able to just whip one out. Therefore it's usually easier for me to write a solution that I know takes VASTLY longer than is necessary, because I can write it EVEN MORE VASTLY faster.
If it takes 20 minutes for that list comprehension to run, that's still less time than if I'd spent 45 minutes testing the recursive function I barely understand :)
 
def best_change(due,coins):
    if due <= 0.001:return []
    next_coin = max([c for c in coins if (due-c) > -0.001])
    return [ next_coin ] + best_change(due-next_coin,coins)


print best_change(2.03,[0.01,0.05,0.10,0.25,0.50,1.00])
 
10:59 PM
this is actually all_change though
not best_change :)
I've actually gone through the "making change" tutorial on enough different languages that THAT one I feel like I could do fairly well.
 
That and recursively flattening a list are literally the only two recursive solutions I feel confident in lol
 
I doubt that
def gcd(x,y):
that one
i bet you got cold too
 
def gcd(x,y):
    import fractions
    return fractions.gcd(x,y)
:)
 
:P
cheater
 
11:10 PM
I think my first reaction to recursive solutions was something like: "Well, they're generally slower to run, but much faster to write if you know how they work. How about if I just don't learn how they work, then learn iterative solutions that much better?"
A little naive -- but so was I :P
 
11:36 PM
meh 99.99999% of the time you are right .... especially in python
 
11:55 PM
Hi all.
I'm having some issues with my homework and wanted to see if someone could just see what they think of it at least.
Its small.
 

« first day (1629 days earlier)      last day (3317 days later) »