New submission from Zbigniew Braniecki <zbigniew.branie...@gmail.com>:
Python has a very useful function any() that will iterate over a list and break on the first matching case. Now, it would be great to have similar function but with: a) ability to use a callback for matching test b) that would return the first match so something like: key = first(['es-AR','es','en-US'], lambda x:self._value.has_key(x)) instead of: for k in ['es-AR','es','en-US']: if self._value.has_key(k): key = k break It would be also nice to be able to capture the first match and return it: value = first(['es-AR','es','en-US'], lambda x:self._value[x]) I'm not sure which one is more generically applicable. ---------- components: None messages: 89879 nosy: gandalf severity: normal status: open title: Add first() function that would take first matching case from an iterator versions: Python 3.1 _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue6379> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com