Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Five-line solution to the Subset-sum problem (Python) (stackoverflow.com)
2 points by varrakesh on Feb 25, 2013 | hide | past | favorite | 1 comment


Interesting to see actual use of sets on Python. For those like me not familiar with the syntax there, the OR-ing (|=) is just Union minus Intersection (because all elements of a Set are unique).

    >>> {1,2,3} | {2,4,6}
    set([1, 2, 3, 4, 6])
By the way, AND-ing would be a straight intersection

    >>> {1,2,3} & {2,4,6}
    set([2])




Consider applying for YC's Summer 2026 batch! Applications are open till May 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: