Operating on Sequence Types

We can iterate over the items in a sequence s in a variety of useful ways: 

Table : Various ways to iterate over sequences
Python ExpressionComment
for item in siterate over the items of s
for item in sorted(s)iterate over the items of s in order
for item in set(s)iterate over unique elements of s
for item in reversed(s)iterate over elements of s in reverse
for item in set(s).difference(t)iterate over elements of s not in t
for item in random.shuffle(s)iterate over elements of s in random order

0 comments

Popular Posts

无觅相关文章插件,迅速提升网站流量