[Baypiggies] itemgetter function unavailable in linux

Vikram K kpguy1975 at gmail.com
Tue Jun 21 16:08:42 CEST 2011


I have a nested list of the type [['dog,10], ['cat',5], ['dragon',7]]

I need to sort this nested list based on the second element of each element
in the nested list so that i end up with:

[['cat',5], ['dragon',7], ['dog',10]]

This used to be easy. Just use the itemgetter function in the itertools
module. But on my linux machine, to my horror, there is no itemgetter
function to be found in the itertools module.

-----

Python 2.7.2 (default, Jun 21 2011, 09:56:35)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-50)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import itertools
>>> from itertools import itemgetter
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: cannot import name itemgetter
>>> dir(itertools)
['__doc__', '__file__', '__name__', '__package__', 'chain', 'combinations',
'combinations_with_replacement', 'compress', 'count', 'cycle', 'dropwhile',
'groupby', 'ifilter', 'ifilterfalse', 'imap', 'islice', 'izip',
'izip_longest', 'permutations', 'product', 'repeat', 'starmap', 'takewhile',
'tee']
>>>

----------
I am now going to grind away and do it the hard way, but can someone tell me
why the itemgetter function is not available on linux although i have been
using it when programming in windows?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/baypiggies/attachments/20110621/e4b9211f/attachment.html>


More information about the Baypiggies mailing list