2025-09-10:仓库迁移

This commit is contained in:
2025-09-10 16:12:45 +08:00
parent e0e49b0ac9
commit 3130e336a1
146 changed files with 4066 additions and 0 deletions

View File

@@ -0,0 +1,22 @@
from itertools import dropwhile, islice
if __name__ == '__main__':
words = ["#look", "#into", "#my", "eyes", "look", "into", "my", "eyes",
"the", "eyes", "the", "eyes", "the", "eyes", "not", "around", "the",
"eyes", "don't", "look", "around", "the", "eyes", "look", "into",
"my", "eyes", "you're", "under"]
# 想要对可迭代对象进行过滤也可以使用dropwhile函数,比如这里我想过滤掉前几行有#的东西
for i in dropwhile(lambda x : x.startswith('#'), words):
print(i)
# dropwhile会在迭代时对函数进行匹配将符合条件的值丢弃直到出现第一个符合条件的值后停止工作返回所有剩余内容
# 如果你知道需要跳过几个元素那可以直接用islice进行切片操作来过滤
items = ['a', 'b', 'c', 1, 2, 3]
# None表示[3:]
for i in islice(items, 3, None):
print(i)
# 当然,使用列表的过滤方法也可以删除一些不要的东西,但是这样的删除是全局的,而不是仅在开头生效