« first day (1836 days earlier)      last day (3106 days later) » 

2:02 PM
Also, apparently it can just be a function, which I missed. So time to save a ton of bytes.
 
@MorganThrapp That's sublime! And reasonably efficient, given that it's recursive.
 
Futures are being weird you guys :|
 
@PM2Ring Yeah, that's half of why I read code golf. Some of those solutions are just beautiful.
 
user559633
BAD squirts water bottle at javascript
 
user559633
Were you actually talking about Python? Because it's a habit that you want to talk about whatever JS thing you've found sitting at the top of the garbage
 
yeah, trying to do this thing with python, otherwise I'd bother the js room
 
user559633
My bad then, moving back your message.
 
user559633
1 message moved from Python Trash - The Rotating Knives
 
@tristan your put your left foot in, then take your left foot out... :)
 
2:08 PM
Now move your "1 message moved from/to trash" messages to the trash, to fully remove all evidence
 
@MorganThrapp Note I said reasonably efficient. It's O(n^2), because max has to scan the whole (current) list on each recursive call. So you wouldn't do that in real code, even though it's fine for code golf.
 
@PM2Ring Oh, yeah. I wouldn't ever implement golf stuff in my real code, though it has exposed me to parts of stdlib that I wouldn't otherwise know about.
 
@Kevin the keen eyed might pick up on the "←" next to corvid's message though :p
 
user559633
@Kevin I'm fine leaving it there :)
 
@MorganThrapp Sure. Still, be wary that doing too much code golf will teach your brain weird habits. :)
 
2:13 PM
@PM2Ring Heheh, fair point.
 
2:32 PM
Hey guys, here is an interesting simple question that I won't bother using the site for. if I have a regular for loop that does some action and then waits in between doing each iteration. Is there a canonical or most pythonic way of skipping the last wait? For instance, if i do a sleep(10) each iteration, how do I make it not sleep on the last iteration? I know many solutions are possible, question is if there is a best way? Thanks my friendly cabbages!
@JonClements I didn't recognize your new gravatar! funny! (But I am nostalgic for the old one) :)
 
@InbarRose I would use enumerate around the iterator of the for and then compare the index with the len of the iterator. If they match, it's the last iteration.
 
Agreed. It's not beautiful, but it's better than the alternatives.
 
@MorganThrapp Yes, clearly. But that seems sloppy. :( I was hoping there was some elegant solution somewhere.
 
@InbarRose Haha... who knows - maybe one day :)
 
@InbarRose Yeah, I wish there was too. :/ I had that same problem recently, and that was the best I could find.
 
2:35 PM
Like, I feel like I want to do a sleep(10).join(loop) :P type of thing.
Anyway, I guess it's just a pipe dream
 
[f() for f in func_join(functools.partial(sleep, 10), [functools.partial(some_function, item) for item in seq])]
You'll have to write your own func_join though
 
And I suspect func_join would have to use that same trick.
 
Yep.
See above message re: better than the alternatives
 
Anonymous
Is there any good python guide for beginners? I have finished the codeacadamy tutorials, but there is so much basic stuff missing.
 
@samayo The official tutorial is good.
 
2:38 PM
Okay, well. Thanks for the input, I will just do the enumerate thing like I originally intended, just wanted to see if maybe someone had a cool trick they could show me. Until next time folks! :)
 
Anonymous
@MorganThrapp The official is always good, but not for beginners :/
 
@Inbar bah - was just writing you one! :(
 
@samayo That list has some others that are good for beginners.
 
Anonymous
@MorganThrapp From a first glance, "diveintopython3" look just like what I was looking for. Thanks
 
@JonClements You are welcome to :)
I remind you. I am always lurking, I just focus much more on work than I used to. Team Leader and all. :)
 
2:41 PM
def blah(iterable):
    it = iter(iterable)
    val = next(it)
    while True:
        yield val
        val = next(it)
        yield 'sleep'
list(blah([1, 2, 3])) then gives you [1, 'sleep', 2, 'sleep', 3]
 
hmmmm
interesting idea
 
but its not exactly plug-n-play
 
Works for arbitrary iterables though - so bonus
 
bleh... I think I need to order the done callbacks of a future to make it work. Do callbacks execute in order?
 
@JonClements so I would need to check in my main loop if the item is 'sleep' or not, if so i would sleep, if not i would carry on?
seems actually less pythonic then checking if you are at the last loop.
for idx, val in enumerate(collection, start=1):
	work(val) # do work
	if idx == len(collection):
		break
	sleep(10)
 
@InbarRose Do the sleep first.
>>> for i, j in enumerate('ABCD'):
...     if i:
...         print('sleep here')
...     print(j)
...
A
sleep here
B
sleep here
C
sleep here
D
>>>
 
When does a generator raise stopiteration? Couldn't you do this:
def blah(iterable):
    it = iter(iterable)
    val = next(it)
    while True:
        yield val
        val = next(it)
        sleep(2)
Because it should raise StopIteration on the val = next(it) when it tries to access past the last element.
Which should stop the last sleep from running.
 
@PatrickMaupin hmmm. interesting, because the enumerator starts at 0 which is False.
@PatrickMaupin I like this solution, it's exactly the kind of clever trick I was hoping to find.,
 
Glad I could help. It's a product of my (literally) fevered mind. The coughing and fever are bad enough, it's the sweating along with the fever I can't stand. Will my body make its mind up?
 
2:52 PM
for idx, val in enumerate(collection):
	if idx:
		sleep(10)
	work(val) # do work
 
Err... well - it's a redundant if check and return of an idx
 
@JonClements how so?
 
That's almost exactly the sample code I wrote and then deleted because Morgan suggested something similar. Although looking back I see he recommended skipping the last sleep rather than the first
 
@MorganThrapp err... isn't that what I wrote - except you've just put sleep(2) there? :p
 
@Kevin Yes, my original thought was also to skip the last one if the index was the length of the list. But this seems like a nicer trick.
 
2:54 PM
@JonClements Well, sort of. Except it sleeps in the function instead of yielding sleep and checking for that value outside of the function.
 
@InbarRose: How about:
import time

def g(n):
    f = lambda :time.sleep(.5)
    fnull = lambda: None
    for i in range(n):
        yield f
    while True:
        yield fnull

sleeper = g(5)
for i in range(10):
    print(i)
    next(sleeper)()
 
@InbarRose I think what Jon is trying to say is that you're checking for whether it's the last/not the first on every loop, when that's something you know up front. He's absolutely right, and this wouldn't always be the best way to do it.
 
Oh... I was just putting yield 'sleep' in there to demonstrate the "flow" - not to act on 'sleep'
 
@JonClements Ahhh, gotcha.
 
bit difficult to show output of when the sleep was occurring if you don't show it :)
 
2:56 PM
@PatrickMaupin Right, well in my specific case each iteration takes a long time to run, the if check/call is negligible
 
(just prove it occurs after each element as long as it's not the last one)
 
@PM2Ring this also seems a bit excessive.
 
He gets paid by the line.
 
stackoverflow.com/questions/33348898/… off-topic. Why doesn't this work.
 
3:01 PM
@PatrickMaupin :) It could be condensed considerably by using itertools repeat & chain. And it could be made more general by passing the lambda :time.sleep(.5) is as an arg to the generator.
 
@PM2Ring but why the imports when simple yielding does it all for you - agreed though, just add an argument for a callable
 
DSM
Morning cabbage for all.
 
hey DSM
 
@JonClements Agreed. I don't think I've ever used itertools.repeat; I was just mentioning what's possible.
 
3:04 PM
Well - looks like Inbar's happy with boring old enumerate :p
 
@JonClements Yipee! Boring old enumerate :)
 
How can i 'effectively' compare a list of unequal, unordered parameters together and print out the differences? I've been messing around with Difflib but I can't seem to get a result that just shows the differences of one list compared to the other. I posted a question a couple days ago but still confused on how i can reach this goal.
0
A: Comparing a list of different sizes and data to output the difference

mcubikThe underlying problem in your program is the problem of finding the difference between two sequences, which is a derivation of the Longest Common Subsequence Problem (LCS, see https://en.wikipedia.org/wiki/Longest_common_subsequence_problem). Its solution is not straightforward. In Python you ca...

 
@JeanP In your example, you can do it by just stepping line by line in the two files - will it always be that ordered?
 
@JeanP Have you tried following the top answer? With dict?
 
3:11 PM
@jonrsharpe for my current program it will but down the line i want to experiment without the files being ordered.
 
@JeanP so does order of the outputs matter? Should it follow one file, or the other, or is following neither OK?
 
@QuestionC Yes i have however i in my program i am trying to use a list rather than a dictionary so i can better understand how comparing lists works.
 
@JeanP you should use the most appropriate data structure for what you're doing (a dictionary, if the order doesn't matter). Did that answer actually get you the output you wanted?
 
@jonrsharpe No, the order of the output.txt file does not matter it could be randomized output but they just have to be the correct output.
@jonrsharpe Alright I was hoping to be able to do this with a List but ill just have to switch to a dictionary in this case.
 
All "Comparing lists" problems have the first step "Turn it into a set or dict". =)
 
3:16 PM
You said "Remember I do not care if a parameter exists in TextB.txt but not in textA.txt; what I care is that if a parameter exists in textA.txt and NOT in textB.txt". And the efficient way to do that test is to store the data from textB in a dict. You could keep textA as a list, and iterate over it, testing each line against the textB dict.
 
If you want to be firm about only using a list, then you have to sort the lists to get it reasonably efficient.
 
Alright, I was curious to see if i was able to do this with a list. Maybe I can but dictionary would be much easier to execute than using a list.
Hmmm thats an excellent idea @PM2Ring I'll try that now. Thank you.
 
You can do it with a list. It's just more work for no reason, and we're generally lazy folk.
 
I was thinking of using either two lists or two dictionaries, never occurred to me to use one of each.
And yeah @QuestionC I should do it the lazy method
 
One benefit of keeping textA as a list (apart from saving the time & RAM it would take converting it to a dict) is that your output will reflect the ordering of the data in textA.
 
3:20 PM
It doesn't even need to be a list, just iterate over the file line-by-line.
 
@jonrsharpe Good point!
 
Well, the reason it is a list currently is because my actual file is a huge mess of data and strings, so i search through the file and output the lines i need into a list. Because if would were to go thru the files that would be 2000 lines of garbage data
The one i used in my question was just an example so i can work backwards and learn lol
 
But if you have the rules to filter it into the list, surely you have the rules to skip the lines you don't want while iterating?
 
Yeah i do, duh
i meant that duh towards myself not you lol
 
cbg
I discovered very strange behavior in Python just now...
 
3:27 PM
cbg direprobs
 
Try this in the interactive prompts and see what you'll get: >>> _ = 200 then >>> del _ and then >>> _ prints 200, you'll find it again not deleted, but if you try del _ again you'll get an error that the name doesn't exist
hahaha
 
>>> _ = 200
>>> _
200
>>> del _
>>> _
200
>>> _
200
 
>>> _ = 200
>>> del _
>>> _
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name '_' is not defined
 
There's a post about this somewhere, but it's because _ is special cased in some shells.
 
Really ? I just tried it again and It worked as it supposed to!!
 
3:32 PM
100
A: Assigning a value to single underscore _ in Python/IPython interpreter

Martijn PietersThe Python interpreter assigns the last expression value to _. This behaviour is limited to the REPL interpreter only, and is intended to assist in interactive coding sessions: >>> import math >>> math.pow(3.0, 5) 243.0 >>> result = _ >>> result 243.0 The standard Python interpreter goes to s...

> The standard Python interpreter goes to some length to not trample on user-defined values though; if you yourself assign something else to _ then the interpreter will not overwrite that
 
@jonrsharpe: I added a comment to the class attributes / XY problem guy's question, but I don't hold much hope that it'll help. :)
There's probably a simple way to do what you want that doesn't require you to clutter your equations with prefixes. But it's hard for us to help you when you still haven't explained what you're really trying to do. We don't need (or want) to see 100 equations, but a simple, minimal, example would be helpful: it'd show us what you're trying to achieve, and it would make it easier for us to explain what's wrong with your current approach. — PM 2Ring 4 mins ago
 
Yes, I think their simple example is too simple to represent their issue.
@MorganThrapp because I tried both OP's problem and this code, I am experiencing the same error as OP when am trying his code, and with this one, you could get the answer without the error. — user 12321 27 mins ago
I simply do not believe that!
 
@jonrsharpe Yeah, I'm extremely sceptical.
 
I remember that from earlier this morning...There definitely is something else going on that OP hasn't shared yet.
 
DSM
Yeah, like maybe file1 imports file2 at the start. That would generate AttributeError: 'module' object has no attribute 'x'. I can't think of any way user12321's code would do what it says he does.
 
3:42 PM
rhubarb
 
rbrb PM
 
@jonrsharpe just deleted it
 
@JonClements thanks other Jon!
 
DSM
SO users are really annoying me today for some reason. Maybe it's a day to take a breather and get some Real Work(tm) done. :-)
 
Always a good plan.
Getting paid for your work. A radical notion.
 
@DSM Congrats for getting 100,000 :-)
 
4:16 PM
Before I work it out myself, is there a formula f(x,y) that tells you the number of ways to write x as the sum of y non-negative numbers? Ex. f(3,2) == 4 because 3 == 0+3 == 1+2 == 2+1 == 3+0
 
re-cbg
 
cbg @vaul and congrats on getting the py gold
 
@Kevin Well, for y of 2 it's always going to be x+1, as near as I can tell.
 
f(4,2) 0+4 1+3 2+2 3+1 4+0 .... @Morgan seems rite
Are you a wizard? <insert meme here>
 
@BhargavRao thank you :)
 
DSM
@Kevin: yes, and it's kind of fun to work it out yourself..
 
Dinner time - rbrb
 
It's going to be binomial, isn't it. Everything always turns out to be binomial.
 
DSM
Things would be much harder if you didn't want to distinguish 1+2 from 2+1.
I don't think we have the consecutive restriction here, though.
 
Right, hence the validity of [0,3]
 
4:25 PM
I misread that question. :P
 
To give context, I am trying to brute force section B of this question and I want to know how many cases I need to iterate through.
If we add the additional restriction "each number must be a single digit", then I think f(20,10) is somewhere around ten million
Oh, my program just finished executing after five minutes. The only solution is [1, 7, 3, 2, 1, 1, 1, 2, 1, 1].
 
Now to do the follow-up which has no single digit restriction
 
Now you've got me reading about partition theory. It doesn't use 0 as a positive digit, but I'm sure it's modifiable.
 
Having not read the thing you linked, I agree. I think g(x,y) = f(x+y,y) if g is "f, except 0 isn't allowed"
Pretty sure no solution exists for the follow-up, since my program didn't find one. But an actual proof would get more points.
 
4:39 PM
Crap, I just missed a math problem didn't I?
 
@Kevin No known closed solutions exist, afaik. I think there might be asymptotic expressions.
 
DSM
Aaargh, I got distracted into an actual meeting. There's no handy closed-form expression for the partition numbers, but in the case where we distinguish 1+2 from 2+1 the answers to Kevin's original problem are figurate.
 
DSM
5:01 PM
@JeanP: that is the craziest dictionary I've seen in a while. That doesn't seem like a very useful form to store data in.
 
I'm using excel to generate Python. Someone please kill me.
 
DSM
Look at it as finding a way to springboard back into sanity even from the unlikeliest of locations.
 
5:17 PM
That's a little better I guess.
 
Years ago I was tasked with writing a program for a co-worker. There was no freedom in its behavior, but my co-workers are well enough trained to understand they aren't altering my preferred language. So this program, written in Python, read Excel spreadsheets and generated programmatic test-cases in TCL.
 
How does one use Excel to generate Python?
 
@QuestionC wat?
 
@DSM what would you recommend in my situation then?
 
A lot of engineers seem to think that Excel is a peachy-keen front-end. I hate it, but often support it. I've written Python that reads Excel to generate all sorts of weird cruft.
 
5:20 PM
@QuestionC I have a flat file that I'm parsing, the excel spreadsheet has the layout of the file, so I wrote = LOWER(CONCATENATE("self.", SUBSTITUTE(A2, " ", "_"), " = line[", C2, ":", D2, "]")) to generate the code for my __init__ for the file parser.
So I end up with e.g. self.section = line[3:5]
For all 80 field definitions.
 
So why wouldn't you use xlrd to keep all the Python out of the spreadsheet?
 
@PatrickMaupin I'm copying and pasting the generated values into pycharm. This is just a one off thing.
 
Nothing is ever just a one-off thing.
 
Perfect time for a 'Your mum' joke...
 
Especially not the things that are purported to be one-off things.
I don't often joke about your mother, but when I do, it won't be about something as serious as one-off-ness.
 
5:26 PM
sorry...this is necessary, only because programming, and your mom jokes
 
Having the complicated-enough-for-a-spreadsheet file layout expressed as code sounds really bad for the next guy to see the code.
 
@QuestionC Eh, I'm the only one who's going to be working on this. It's converting a client's historical data to our system as part of on-boarding.
 
@idjaw I thought the rules were that you had to capitalize Stack Overflow.
 
I meme failed.
 
I'd parse the excel sheet as a CSV. But that motivation may be purely driven by not wanting to learn how to do things in excel.
 
5:31 PM
Unfortunately, some spreadsheets have multiple sheets.
 
Well, the excel sheet was something I wrote up because the format they gave us was a near unreadable .doc.
 
My sympathy is quickly eroding.
 
DSM
@JeanP: a dictionary like {'ATP=15': 'ATP=15', 'PAN=10':'PAN=10', 'YUP="1230"':'YUP="1230"', 'DATA=45':'DATA=45'} doesn't make much sense. The keys are the same as the values, so there's no extra information there. ATP=15 looks like an association between ATP and 15, but there's no way to access 15 knowing ATP without looping over the lot of them.
 
@DSM yeah i completely forgot to format and split/strip the dictionary into something like {'ATP': '15'}
i had a homer Simpson duh moment there.
 
DSM
I would have guessed you wanted {"ATP": 15} -- the quotes around "1230" and the absence of them around 10 makes it seem like they're meant to distinguish types. No way to be sure, though.
 
5:39 PM
Ah its that some values are ints and some are strings
I'll edit so it's clear, thank you I really appreciate it
 
DSM
@MorganThrapp: ouch. In your place I think I'd have extracted the layout data from Excel immediately into Python rather than gone the codegen route.
 
6:08 PM
Do we have a dupe target for "every branch of your recursive function needs a return statement"?
 
hi all
 
That's a weird looking fib function, even when the returns are right.
 
after returning multiple values from function is it possible to use a specific index from the returned function or do i have to unpack it first?
 
It's just a tuple
Unless/until you unpack it.
 
You can index it without unpacking:
>>> "Hello world".split()
['Hello', 'world']
>>> "Hello world".split()[0]
'Hello'
In general, (any_expression_goes_here)[index] is legal syntax
 
6:14 PM
A ha!
thanks
 
(not to be confused with "definitely will run and not crash and not give you the wrong answer")
 
i was putting the index before the paren
 
"Hello world".split([0]) is also legal syntax, but will almost certainly not give you what you want.
In general, f(thing)[0] and f(thing[0]) are very different
 
if my return statement is --> return (value, dict)
 
style tip: return value, dict is also legal
 
6:16 PM
and calling the function --> myfunction('hey')[0]
i would get the value?
 
Yeah
 
thats actually pretty freakin cool.
new to python
thanks
 
that's hilarious it took that long
no more copying to notepad to read it :P
 
20 characters wide should be enough window space for anybody.
 
6:25 PM
I heard a rumor that the cmd.exe window is also expandable (width and height!!) and you can copy/paste with normal shortcut keys .... but it didnt seem to work on my windows 10 :(
 
You should return it and get a refund. Faulty product. :^)
 
You need Windows 10 Enterprise Premium Plus for that.
 
I wish i understood openvpn better ... maybe i just need to read this shell script ...
 
Anyone read any good books/tutorials on async in python?
 
One day you will conquer async corvid.
 
6:29 PM
threading.Thread(target=self.DoIt).start()
there you go
 
Async is annoying to manage, especially with too many threads :\
 
Async is easy and fun.
 
I sync Athink is fun.
 
I think async and sync are both about as fun as a paintbrush or a hammer
 
DSM
6:44 PM
@Kevin: didn't we talk about making a canonical forgotten-return Q/A at some point?
 
That sounds like something that could have happened, yeah.
 
So I've extended the logging.Logger object with a new method - MyLogger I have a getMyLogger function, which simply returns MyLogger(name). I want to expand it to logging._acquireLock(), try: getLoggerClass; setLoggerClass(MyLogger); logger = getLogger(name); setLoggerClass(old_class) finally: logging._releaseLock(). But we have a large code base. Currently it's easy to reason about. Making the logging.Manager handle it will probably make it harder to reason about for the adopters. Thoughts?
 
Hello fellows
 
user559633
i'm a half lizard centaur, not a "fellow"
 
user559633
also, hi, welcome @rp372
 
6:57 PM
I'm not your fellow, guy.
 
r-r-r-r-reference breaker
 
user559633
@Kevin great, now we all have to reboot. thanks, jerk
 
So to reboot, anyone know logging well enough to be of service?
 
user559633
so to reboot reboot: "If nobody responds to your question, that means no-one in the room is able to help.."
 
@AaronHall I've been known to wear plaid from time to time.
 
7:07 PM
That's usually the case... (response applies to both)
 
my logger is usually print
 
user559633
where's my "it appears you're trying to create a logging queue" clippy
 
It's a basic Logger, with a method to log events to a central facility like an OODB. This is not for verbose/debug logging, but rather important events.
 
user559633
isn't the point of an oodb to free your brain from hard problems so you can focus on creating tech debt?
 
The Manager in logging assembles a hierarchy of loggers (why? I think one could set a handler's level at a package level, maybe?) and uses a 1 to 1 name to logger mapping to avoid creating extra loggers unnecessarily.
We have a perhaps ill-advised reimplementation of a manager somewhere, and they're asking me at what point do they insert my logger. I'm telling them to use my getMyLogger fn, but 1) want it to work seamlessly and 2) want it to be easy to reason about (but logging isn't usually...) so I think I need to forget 2), which means I should do my getMyLogger method the way I first described... :/
 
user559633
7:17 PM
the python stdlib logging module is pretty easy to reason about until someone overcomplicates it with a "convenience" wrapper
 
I do that often
 
user559633
me too!
 
I just don't log anything, ever. Makes things much easier.
 
I just log everything
so within 2 days you have a 2 gigabyte logfile
 
user559633
syslog and logrotate. done
 
7:26 PM
They got some code reuse by subclassing the logging.LoggerAdapter. Net effect was something like 2 extra lines of code that required a dozen more, and 60 lines of documentation...
 
cbg all
 
stackoverflow.com/q/33353985 "follow these instructions for me"
 
user559633
I can't figure out if that's an interview question or what. I wasn't aware that schools were teaching basic sysadmin stuff nowadays
 
they don't, usually. And even if they do, it's not super specific to language or technology. My guess is that this is either an interview question, or OP is attending college (not university) for a very specific skill set
 
maybe some online course?
 
7:35 PM
possibly
 
Maybe they thought it would be a fun exercise for SO users
 
user559633
Who uses "firstly"
 
These pretzels are making me firstly
 
Academics writing homeworks for online courses?
 
if i put a return statement in a for loop will i break anything with that return being invoked multiple times?
 
7:45 PM
return only happens one time
 
user559633
YORO
 
If you're thinking of your function like that, you probably need generators. There's some really good answers about how to use yield here in SO if you dig deeply enough.
 
thank you i will look into that
 
user559633
or, if you can only do something when you have all the data, have the for loop update a another data structure
 
Did you know you can delegate to subgenerators in Python 3 with yield?
 
7:48 PM
I want to loop through a dict. If a value appears in the dict then return "failed', else return "passed"
 
user559633
    my_filtered_list = []
    for n in my_raw_list:
        # do some logic
        my_filtered_list.append(new_value)

    #this runs sequentially, so we can just use the new list here
 
user559633
oh, are you printing this? if so, yeah, yield is fine
 
but i am afraid that it will either keep returning (well not anymore) or just return once and not go through the rest of the dict
 
user559633
@AaronHall what do you mean?
 
set intersection with valuesview in python 2.7, values in 3+
 
7:49 PM
def f(d, v):
    for key in d:
        if d[key] == v:
            return "failed"
    return "passed"
 
user559633
oh, you mean yield from x()
 
Hot tip: instead of returning strings indicating a success value, return a boolean
 
that's right
 
user559633
Shitty tip: subprocess to another python interpreter for each line
 
I never understood yield from and all the changes to yielding in py3. Does anyone feel like taking 20 minutes to explain this to me?
 
7:51 PM
Yeah, I never quite got it either.
 
@mri3 That's a common logic error. Putting an unconditional return inside a loop usually means you need one conditional return in the loop, and an unconditional one outside the loop.
 
there's a good answer on that here on SO. read it and ask me questions if you still have them.
 
DSM
Oh, hey, @inspectorG4dget!
 
heya @DSM! Long time. How've you been?
 
user559633
@AaronHall Are you referencing e-satis's answer here? stackoverflow.com/questions/231767/…
 
7:52 PM
@AaronHall link please?
 
def check_all_items():
    #checks that all the items are thing
    for item in items:
        if not is_thing(item):
            return False
    return True

def check_any_items():
    #checks that at least one item is thing
    for item in items:
        if is_thing(item):
            return True
    return False
 
DSM
Pretty good! Counting the days to my Christmas vacation, but muddling through.
 
... Or you can just write a list comprehension with built-in functions any or all, but that is beyond the scope of Kevin's Turbo Do-It-Yourself Programming 101
 
Use the link Tristan gave, and search for "yield from" - e satis didn't quite get that far
 
thanks @Kevin
 
7:55 PM
@inspectorG4dget AFAIK yield from f() is exactly equivalent to for item in f(): yield item. It's really just for the convenience of turning two common lines of code into one.
 
user559633
@AaronHall If you wanted to just say "i wrote some words about it at this url" then provide the url with some framing text instead of "the ancients have whispered about a URL, just talk to the three eyed owl and tell him 'whom', and he will open a door to the caterpillar's layer where my words have been woven into the tapestry of existence"
5
 
Hey Aaron, we've talked about this before: you've lost the privilege of referencing your own answers due the constant spammy feeling every time you do it. Obliquely referencing it wink wink is no better.
 
DSM
@Kevin: you can do more than just a loop, though, because you can get values (x = yield from something()).
 
@Kevin: I'm a total yield noob. Could you write me a recursive function that uses yield, please?
 
That's funny, I actually wrote one today. I'll go fetch it hither.
 
7:58 PM
yippee!
 
Here it is at the bottom of my answer. It calculates all the ways you can take nums number of positive digits and add them up to x
 

« first day (1836 days earlier)      last day (3106 days later) »