List
Rod Haper
rhaper at houston.rr.com
Sun Jun 2 19:57:04 EDT 2002
Gold Fish wrote:
> What i am trying to do is that i got one biglist don't know how big is it
> say list1 then i like to divided into some small sublists. These sublists
> will have some elements in the biglist for example 3 elements maximum in
> each sublist. So if the biglist got 10 elements then it'll be divided into
> 4 sublists the first 3 will have 3 elements and the last one will have one
> elements.
>
[rodh at rodh rodh]$ python
Python 2.2.1 (#1, Apr 20 2002, 20:12:24)
[GCC 2.96 20000731 (Red Hat Linux 7.1 2.96-85)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> bigList = ['a','b','c','d','e','f','g','h','i','j']
>>> subLists = []
>>> subListSize = 3
>>> for i in range(0,len(bigList),subListSize):
... subLists.append(bigList[i:i+subListSize])
...
>>> subLists
[['a', 'b', 'c'], ['d', 'e', 'f'], ['g', 'h', 'i'], ['j']]
>>>
Is this what you are looking for?
--
Rod
+----------------------------------+
| Rod Haper, rhaper at houston.rr.com |
| There is a better way ... |
| LAP => Linux + Ada95 + Python |
+----------------------------------+
More information about the Python-list
mailing list