python - Removing every third item from list (Deleting entries at regular interval in list) -


i want remove every 3rd item list. example:

list1 = list(['a','b','c','d','e','f','g','h','i','j']) 

after removing indexes multiple of 3 list be:

['a','b','d','e','g','h','j'] 

how can achieve this?

you may use enumerate():

>>> x = ['a','b','c','d','e','f','g','h','i','j'] >>> [i j, in enumerate(x) if (j+1)%3] ['a', 'b', 'd', 'e', 'g', 'h', 'j'] 

alternatively, may create copy of list , delete values @ interval. example:

>>> y = list(x) # x list mentioned in above example >>> del y[2::3] # y[2::3] = ['c', 'f', 'i'] >>> y ['a', 'b', 'd', 'e', 'g', 'h', 'j'] 

Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -