• funkless_eck@sh.itjust.works
    link
    fedilink
    arrow-up
    1
    arrow-down
    1
    ·
    26 days ago

    the list is the helpful part to understanding it.

    it would be terrible if, with bar being a list and foo being a member of the list

     if foo in bar: return true
    

    modified the list. So yeah, you want to look at the list not edit the list, it’s a pointer.

    • lime!@feddit.nu
      link
      fedilink
      arrow-up
      3
      ·
      26 days ago

      other way round surely? if you want to modify the original object, use a pointer. if you don’t, use a copy.

    • gerryflap@feddit.nl
      link
      fedilink
      arrow-up
      1
      ·
      26 days ago

      Your example doesn’t make sense to me. Why would you modify the entire list by checking if something is in it? Also, you can totally edit the list via a pointer, that’s how you’re supposed to edit the list if you want any performance. Otherwise you’d be copying the list on every modification, which is terribly inefficient