Explain python cycle with lambdas, please

Ais*_*sys 0 python lambda cycle xlsx

i need to edit code for my needs, but unluckily i don't have a choice to rewrite from zero, so i must understand what is this, because deadline is in 11 hours. halp a junior find his job

    if text and segment:
        if "Office" in segment:
            if True in list(map(lambda x: x in text, _classes[_classB][0])):
                return "????? ?"
        if "Warehouse" in segment:
            if True in list(map(lambda x: x in text, _classes[_classB][0])) or \
                    True in list(map(lambda x: x in text and True in [w not in text for w in _classes[_classA][0]], 
                        _classes[_classB][1])):

                return "Class B"    
        return ""
    return ""
Run Code Online (Sandbox Code Playgroud)

may you eplain what the hell is

 True in list(map(lambda x: x in text and True in [w not in text for w in _classes[_classA][0]],_classes[_classB][1])):
Run Code Online (Sandbox Code Playgroud)

or something like "unlambda"? big thanks

UPD: i need to add a rule: "if landsize is >9000 then ..." where landsize in another column"

a_g*_*est 5

Okay, so first let's reformat it to get a better point of view:

True in list(map(
    lambda x: (
        x in text 
        and True in [
            w not in text
            for w in _classes[_classA][0]
        ],
    _classes[_classB][1]
))
Run Code Online (Sandbox Code Playgroud)

Well it still looks like madness, but luckily we can simplify further:

  • in and not in are going to give True or False but so instead of checking True in ... we can do any(...),
  • the inner list comprehension [...] is independent of the outer map, so we can refactor it out,
  • since the x in text and the following w condition are and'ed, we can pull the w condition in front to shortcut in case it is False

So we obtain:

w_condition = any(w not in text for w in _classes[_classA][0])
result = w_condition and any(x in text for x in _classes[_classB][1])
Run Code Online (Sandbox Code Playgroud)

Basically this seems to check that the text contains not all of _classes[_classA][0] and at least one of _classes[_classB][1]. Why it does that is up to you to judge.