Introducing List Filtering,,li = ['a', '
Introducing List Filtering,,li = ['a', '
li = ['a', 'mpilgrim', 'foo', 'b', 'c', 'b', 'd', 'd'] print [elem for elem in li if len(elem) > 1] print [elem for elem in li if elem != 'b'] print [elem for elem in li if li.count(elem) == 1]
相关内容
- List for iteration,listforiteration,for x in [1,
- For Statements,forstatements,a = ['cat',
- To iterate over the indices of a sequence, combine range() and len(),
- Sort and reverse elements in list,reverseelements,scores = ['1
- List slice assignment: delete and insert,sliceassignment,L = ['spam
- List slicing,listslicing,numbers = [1
- A tuple consists of a number of values separated by commas,tuplecom
- tuple assignment,tuple,nudge = 1win
- Empty tuples are constructed by an empty pair of parentheses,tuples
- List inside a tuple,listinsidetuple,T = (1, [2,
评论关闭