reduction
MRAB
python at mrabarnett.plus.com
Wed Jun 1 18:06:50 EDT 2016
On 2016-06-01 22:44, Lawrence D’Oliveiro wrote:
> On Wednesday, June 1, 2016 at 2:22:42 AM UTC+12, Fillmore wrote:
>> ['a','b','c','l'] => 0 # If "l" is in my data I have a zero
>> ['a','b','c'] => 1 # or a more generic match will do the job
>
> for entry in \
> (
> ['a','b','c','l'],
> ['a','b','c'],
> ) \
> :
> flag = int(not any(m == "l" for m in this_list))
> ... # flag is the 1/0 code you’re looking for ...
> #end for
>
What is "this_list"? The main 'for' loop has "entry".
A shorter way is to use sets:
for entry in \
(
['a','b','c','l'],
['a','b','c'],
) \
:
flag = int("l" not in set(entry))
... # flag is the 1/0 code you’re looking for ...
#end for
More information about the Python-list
mailing list