#!/usr/bin/env python
# -*- coding: utf-8 -*-

# 直接遍历删除
l = [1, 2, 3, 4]

for i in l:
    if i != 4:
        l.remove(i)

print l

# 利用index来遍历删除
l = [1, 2, 3, 4]
# l = [1, 2, 3, 4, 5]

for i in range(len(l)):
    if l[i] == 4:
        del l[i]

print l

# filter
l = [1, 2, 3, 4]
l = filter(lambda x: x != 4, l)
print l

# 产生一个新序列, 赋值给l

l = [1, 2, 3, 4]
l = [i for i in l if i != 4]
print l


# 建立新的list存放要删除的元素
l = [1,2,3,4]
dellist = []
for i in l:
    if i == 4:
        dellist.append(i)

for i in dellist:
    l.remove(i)

l = [1,2,3,4]
ll = l
l.remove(1)

print l
print ll
print id(l)
print id(ll)

@@ -248,16 +248,152 @@
 rint l%0A%0A
+print(%22%E5%80%92%E5%BA%8F%E5%88%A0%E9%99%A4%22)%0A%0A# %E5%80%92%E5%BA%8F%E5%88%A0%E9%99%A4%0Al = %5B1,2,3,4,5%5D%0Afor i in range(len(l) - 1, -1, -1):%0A    print i,l%5Bi%5D%0A    if l%5Bi%5D == 4:%0A        del l%5Bi%5D%0A%0Aprint l%0A%0A
 # filter
@@ -735,8 +735,12 @@
  id(ll)%0A
+%0A%0A%0A%0A

add reverse delete