The performance of itemgetter is slightly better:
>>> f1 = lambda: sorted(w, key=lambda x: x[1])
>>> f2 = lambda: sorted(w, key=itemgetter(1))
>>> timeit(f1)
21.33667682500527
>>> timeit(f2)
16.99106214600033
More Related Contents:
- Change sign of elements with an odd sum of indices
- How to add a label to all words in a file? [closed]
- How to remove English words from a file containing Dari words?
- Function Arguments – Clarification
- How can I read inputs as numbers?
- Using both Python 2.x and Python 3.x in IPython Notebook
- What do ellipsis […] mean in a list?
- Why is a list comprehension so much faster than appending to a list?
- How to print a string at a fixed width?
- How to use pip with Python 3.x alongside Python 2.x
- Why is parenthesis in print voluntary in Python 2.7?
- Why does str(float) return more digits in Python 3 than Python 2?
- Backporting Python 3 open(encoding=”utf-8″) to Python 2
- pip or pip3 to install packages for Python 3?
- Accessing attributes on literals work on all types, but not `int`; why? [duplicate]
- How to print a list with integers without the brackets, commas and no quotes? [duplicate]
- How do I run python 2 and 3 in windows 7? [duplicate]
- Python regex for unicode capitalized words
- Python3 correct way to import relative or absolute?
- Is Python’s order of evaluation of function arguments and operands deterministic (+ where is it documented)?
- Pip freeze vs. pip list
- How to create a Python dictionary with double quotes as default quote format?
- PyOpenGL glutInit NullFunctionError
- How to apply a function to each sublist of a list in python?
- Python 3 urllib produces TypeError: POST data should be bytes or an iterable of bytes. It cannot be of type str
- How to read the last line of a file in Python? [duplicate]
- Multiple keys per value
- WinError 2 The system cannot find the file specified (Python)
- Download YouTube video using Python to a certain directory
- ‘is’ operator behaves unexpectedly with floats