how to duplicate array entries

Steven Howe howe.steven at gmail.com
Mon Jan 11 16:52:26 CET 2010


try
---------------------------------------
#!/usr/bin/env python
from types import ListType, IntType

def array_expander( ar=None, ex=None ):
     if type( ex ) != IntType:
         return []
     if ex <= 0:
         return []
     if type( ar ) != ListType:
         return []
# working code starts here #
     res = []
     for t in ar:
         for x in range( ex ):
             res.append( t )
     return res
# function ends #

res = array_expander( [1,11,3,5], 4 )

print res
---------------------------------------
[1, 1, 1, 1, 11, 11, 11, 11, 3, 3, 3, 3, 5, 5, 5, 5]



-- 
*Kiri-kin-tha's* First Law of Metaphysics is /"Nothing unreal exists."/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20100111/44e1ebac/attachment.html>


More information about the Python-list mailing list