removing list comprehensions in Python 3.0
Ron Adam
rrr at ronadam.com
Sat Jul 9 02:46:57 EDT 2005
Leif K-Brooks wrote:
> Kay Schluehr wrote:
>
>>>>>list.from_str("abc")
>>
>>list("a", "b", "c" )
>
>
>
> I assume we'll also have list.from_list, list.from_tuple,
> list.from_genexp, list.from_xrange, etc.?
List from list isn't needed, nor list from tuple. That's what the * is
for. And for that matter neither is the str.splitchar() either.
class mylist(list):
def __init__(self,*args):
self[:]=args[:]
mylist(*[1,2,3]) -> [1,2,3]
mylist(*(1,2,3)) -> [1,2,3]
mylist(*"abc") -> ['a','b','c']
mylist(1,2,3) -> [1,2,3]
mylist([1],[2]) -> [[1],[2]]
mylist('hello','world') -> ['hello','world']
Works for me. ;-)
I always thought list([1,2,3]) -> [1,2,3] was kind of silly.
Cheers,
Ron
More information about the Python-list
mailing list