我有一個包含很多元素的列表。 我能夠找到一種方法來刪除重複項,空白值和空白。從隱形python列表中刪除特殊字符
剩下的唯一一件事就是:
- 刪除任何東西,包括(AE)的字符串。
- 從列表中刪除包含期內的任何東西(。)
結果列表的順序並不重要。 的最終列表應該只包含:
FinalList = ['eth-1/1/0', 'jh-3/0/1', 'eth-5/0/0','jh-5/9/9']
代碼:
XYList = ['eth-1/1/0', 'ae1', 'eth-1/1/0', 'eth-1/1/0', 'ae1', 'jh-3/0/1','jh-5/9/9', 'jh-3/0/1.3321', 'jh-3/0/1.53', 'ae0', '', 'eth-5/0/0', 'ae0', '', 'eth-5/0/0', 'ae0', 'eth-5/0/0', '', 'jh-2.1.2']
XYUnique = set(XYList)
XYNoBlanks = (filter(None,XY))
RemovedWhitespace = [item.strip() for item in XYNoBlanks]
# the order of the list is not important
# the final result should be
FinalList = ['eth-1/1/0', 'jh-3/0/1', 'eth-5/0/0','jh-5/9/9']
'列表(如果s和'ae'不在s中且'''不在s中],則設置[[對於XY列表中的s,s])) ' –