| Revision 252,
1.2 KB
checked in by shiml, 19 months ago
(diff) |
|
space invaders with ueberwachung. german umlaut ü.
|
| Line | |
|---|
| 1 | # $Id: libutils.py 1.1 2004/12/30 03:56:21 jimb Exp $ |
|---|
| 2 | # Python utility library. |
|---|
| 3 | # Author: Jim Brooks http://www.jimbrooks.org |
|---|
| 4 | # Date: 2004/08 |
|---|
| 5 | # License: GNU General Public License (GPL) |
|---|
| 6 | # Requires: Python 2.3, PyGame, SDL. |
|---|
| 7 | # ============================================================================== |
|---|
| 8 | |
|---|
| 9 | # Prune invalid objects in a list. |
|---|
| 10 | # Requires: Objects in elements have a .valid member. |
|---|
| 11 | # List is flat (no nested sequences). |
|---|
| 12 | # Iterating thru a list and deleting items |
|---|
| 13 | # is an error in Python so a copy is used. |
|---|
| 14 | def PruneList( list ): |
|---|
| 15 | tmp = list[:] # copy list (shallow copy) |
|---|
| 16 | i = -1 |
|---|
| 17 | for obj in tmp: |
|---|
| 18 | i += 1 |
|---|
| 19 | if not obj.valid: |
|---|
| 20 | del list[i] |
|---|
| 21 | i -= 1 |
|---|
| 22 | return |
|---|
| 23 | |
|---|
| 24 | # Prune invalid objects in a list of lists (2D list). |
|---|
| 25 | # Requires: Objects in elements have a .valid member. |
|---|
| 26 | # List must not be deeper than 2 levels. |
|---|
| 27 | def PruneListList( listList ): |
|---|
| 28 | tmpListList = listList[:] # copy list (shallow copy) |
|---|
| 29 | i = -1 |
|---|
| 30 | for list2 in tmpListList: # for each 2nd-level list |
|---|
| 31 | i += 1 |
|---|
| 32 | j = -1 |
|---|
| 33 | for obj in list2: |
|---|
| 34 | j += 1 |
|---|
| 35 | if not obj.valid: |
|---|
| 36 | del listList[i][j] |
|---|
| 37 | j -= 1 |
|---|
| 38 | return |
|---|
Note: See
TracBrowser
for help on using the repository browser.