Passing a second input to itertools deopwhile
This works
def doesnt_contain_character(str,sub):
substring = sub
if substring in str:
return False
else:
return True
doesnt_contain_character('ipsum','a')
but this
string_list = ['lorem', 'ipsum', 'dolor', 'sit', 'amet']
print(list(it.dropwhile(doesnt_contain_character(str,'a'), string_list)))
not because I need to pass 'a'
. In brief all exemple of dropwhile
on the net doesn't need two inputs. Is there a way to do that ?
Why do you insist to use the parameter
str
- thus overwriting one of the main types in python, then do something exactly with this type? Well, typing againstpep8
is somehow tolerated on this site, but using thatstr
makes reading the whole post irritating.Please always provide working code. I guess that
it
is a shorthand foritertools
- but please make our life easier. Please always explain what the code should do, how it is related to some sagemath functionality, and which is the unexpected error / behavior. If there is a "brief example on the net" - please link it. All in all, a question should come as digested as possible, so that potential answerers can go straightforward to the answer - and so that potential readers, now or after the years, can also profit from the question and the answer. Making a question searchable is also a good point. If some functionality insideitertools
is the main issue, then mention it in a clear manner. What is "second input"? This question is downvoted because of repeated and repeated way doing so.How this question is relevant to Sage?
I second the comments already made. I note (with Max) that this is, again, a Python question (and, more fundamentally, a "basic programming" question)...
Furthermore, I have trouble making head and tail of what you want to accomplish. Could you give a couple of examples ? And in what context you have a "second parameter" problem ?
Remember that you can always enclose ("nest" a function as local to another one, which will find the outer function's parameters "naturally".