Better way to negate a boolean list?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?ISO-8859-1?Q?David_Tr=E9mouilles?=

    Better way to negate a boolean list?

    Hi,

    Is there any better (shorter) way to negate a boolean list than:
    >>negated_boole an_list = [not elem for elem in boolean_list]
    ?

    I tried:
    >>map(not, boolean_list)
    but it seems that "not" is not a function.

    Thanks in advance,

    David
  • Paddy

    #2
    Re: Better way to negate a boolean list?

    On Feb 10, 7:46 am, David Trémouilles <david.t...@gma il.comwrote:
    Hi,
    >
    Is there any better (shorter) way to negate a boolean list than:
    >>negated_boole an_list = [not elem for elem in boolean_list]
    ?
    >
    I tried:
    >>map(not, boolean_list)
    but it seems that "not" is not a function.
    >
    Thanks in advance,
    >
    David
    Try [not x for x in boolean_list]

    - Paddy.

    Comment

    • Steve Holden

      #3
      Re: Better way to negate a boolean list?

      Paddy wrote:
      On Feb 10, 7:46 am, David Trémouilles <david.t...@gma il.comwrote:
      >Hi,
      >>
      > Is there any better (shorter) way to negate a boolean list than:
      > >>negated_boole an_list = [not elem for elem in boolean_list]
      >?
      >>
      >I tried:
      > >>map(not, boolean_list)
      >but it seems that "not" is not a function.
      >>
      >Thanks in advance,
      >>
      >David
      >
      Try [not x for x in boolean_list]
      >
      This six-character shortening by renaming the comprehension's bound
      variable was a joke, right?

      regards
      Steve
      --
      Steve Holden +1 571 484 6266 +1 800 494 3119
      Holden Web LLC http://www.holdenweb.com/

      Comment

      • Paddy

        #4
        Re: Better way to negate a boolean list?

        On Feb 10, 1:41 pm, Steve Holden <st...@holdenwe b.comwrote:
        Paddy wrote:
        On Feb 10, 7:46 am, David Trémouilles <david.t...@gma il.comwrote:
        Hi,
        >
        Is there any better (shorter) way to negate a boolean list than:
        >>negated_boole an_list = [not elem for elem in boolean_list]
        ?
        >
        I tried:
        >>map(not, boolean_list)
        but it seems that "not" is not a function.
        >
        Thanks in advance,
        >
        David
        >
        Try [not x for x in boolean_list]
        >
        This six-character shortening by renaming the comprehension's bound
        variable was a joke, right?
        No,
        Of course not!
        It's much worse - I completely missed the line beginning negated_....
        on
        first and second reading.
        I am indeed getting older, although I had thought I was way off my
        dotage.

        - Paddy.

        Comment

        Working...