Slicing a list with non-integer parameter? How?
Husam
h.jehadalwan at student.kun.nl
Sat Oct 6 11:21:17 EDT 2001
More information about the Python-list mailing list
Sat Oct 6 11:21:17 EDT 2001
- Previous message (by thread): PyML
- Next message (by thread): Slicing a list with non-integer parameter? How?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Hi fiends, I'm trying to determine the position of an item in a list in order to delete it by slicing the list with non integer parameter. Code I works just fine. But code II doe's not work: Code 1 with integer values: >> list1=[1,2,3,4] >>> for i in list1: ... if i==2: ... pos=len(list)-len(list[i:]) ... del list[pos-1] ... print list ... [1, 3, 4] Code II with non integer values: >>> list2=['one','two','thrie','four'] >>> for i in list2: ... if i=='drie': ... pos=len(list)-len(list[i:]) ... del list[pos-1] ... print list ... Traceback (innermost last): File "<stdin>", line 3, in ? TypeError: slice index must be int PS: my Python version is 1.5 thanks in advance
- Previous message (by thread): PyML
- Next message (by thread): Slicing a list with non-integer parameter? How?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list