Is there a way to do something like this?
if ['hel','ell','orl'] in 'hello world' :
I want all these lines to appear in the word. If possible, a shorter path than a full multi-line loop recording.
You can do:
if all( x in 'hello world' for x in ['hel','ell','orl'] ): print "Found all of them"
The built-in functions all and any are useful for this kind of thing.
all
any
if all(substr in 'hello world' for substr in ('hel','ell','orl')): # all are contained
The advantage of all() is that it stops being checked as soon as one substr does not match.
all()
substr
A multi-line for loop is the right way to continue. If you donβt like how it looks in your code, extract it into a function, and then you will only have to call one line for the same thing.
for
Source: https://habr.com/ru/post/1343737/More articles:Create a thick arrow using only HTML / CSS - jqueryQTableView: how to do something while editing the beginning and end? - c ++How to rename a file in a zip archive using Ant? - javafree an ABMultiValueRef object - memory-managementLaunch Yaws Applications - erlangc char * question - cMultiplies faster than comparison in .NET? - performancePreventing two instances of an instance from fulfilling the same goal (parallel make) - makefileAre unordered Boost containers readable? - c ++What is the standard way to handle Null dates in .NET. - nullAll Articles