python's sort and sorted

  • sort applies only to the list, returns a list of types.
  • sorted applicable to dictionaries, tuples, and lists.
    # Use method
    to use is sort oflist.sort(cmp=None, key=None, reverse=False)
  • cmp - optional parameter, if this parameter is a method of using the parameter designated for sorting.
  • key - is mainly used for the comparison element, only one parameter, the specific parameter is a function of iteration may be taken from the object, specify one of the elements in the iteration to be sorted.
  • reverse - collation, reverse = True descending, reverse = False ascending (default).
    Cmp canceled parameters in python3.x in does not support directly to the sort () function inside pass up. Transmitted to the ranking function may be configured to implement key.
    The use is sorteda.sorted()
  • Consistent parameters and sort.

Guess you like

Origin www.cnblogs.com/sogeisetsu/p/11407301.html