title: have_same_contents
tags: list,intermediate

Returns True if two lists contain the same elements regardless of order, False otherwise.

Use set() on the combination of both lists to find the unique values.
Iterate over them with a for loop comparing the count() of each unique value in each list.
Return False if the counts do not match for any element, True otherwise.

继续阅读 30秒学会 Python 片段 – have_same_contents.md

Returns the n minimum elements from the provided list.
If n is greater than or equal to the provided list’s length, then return the original list (sorted in ascending order).

Use sorted() to sort the list,[:n]to get the specified number of elements. Omit the second argument,n`, to get a one-element list.

继续阅读 30秒学会 Python 片段 – min_n