objectoriented -?- functional
Walther Neuper
neuper at ist.tugraz.at
Wed Mar 18 06:26:51 EDT 2009
Hi,
loving Java (oo) as well as SML (fun) I use to practice both of them
separately.
Now, with Python I would like to combine 'oo.extend()' with 'functional
map':
Python 2.4.4 (#2, Oct 22 2008, 19:52:44)
[GCC 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> def reverse_(list):
... """list.reverse() returns None; reverse_ returns the reversed
list"""
... list.reverse()
... return list
...
>>> ll = [[11, 'a'], [33, 'b']]
>>> l = ll[:] # make a copy !
>>> l = map(reverse_, l[:]) # make a copy ?
>>> ll.extend(l)
>>> print("ll=", ll)
('ll=', [['a', 11], ['b', 33], ['a', 11], ['b', 33]])
But I expected to get ...
('ll=', [[11, 22], [33, 44], [22, 11], [44, 33]])
... how would that elegantly be achieved with Python ?
Cheers, Walther
--
------------------------------------------------------------------------
Walther Neuper Mailto: neuper at ist.tugraz.at
Institute for Software Technology Tel: +43-(0)316/873-5728
University of Technology Fax: +43-(0)316/873-5706
Graz, Austria Home: www.ist.tugraz.at/neuper
------------------------------------------------------------------------
More information about the Python-list
mailing list