本文整理汇总了Python中linkedlist.LinkedList.filter方法的典型用法代码示例。如果您正苦于以下问题:Python LinkedList.filter方法的具体用法?Python LinkedList.filter怎么用?Python LinkedList.filter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类linkedlist.LinkedList
的用法示例。
在下文中一共展示了LinkedList.filter方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_filter_creates_new_items
# 需要导入模块: from linkedlist import LinkedList [as 别名]
# 或者: from linkedlist.LinkedList import filter [as 别名]
def test_filter_creates_new_items(self):
ll = LinkedList()
item1 = ll.add_to_front(12, 3534536)
ll2 = ll.filter(None)
item2 = ll2.front
assert item1 != item2
assert item1.key == item2.key
assert item2.value == item2.value
示例2: test_map_filter_equal_to_identity
# 需要导入模块: from linkedlist import LinkedList [as 别名]
# 或者: from linkedlist.LinkedList import filter [as 别名]
def test_map_filter_equal_to_identity(self):
ll = LinkedList()
item1 = ll.add_to_front(123, 8907067)
ll2 = ll.filter(None)
item2 = ll2.front
assert item1.key == item2.key
assert item1.value == item2.value
assert ll.length == ll2.length
示例3: test_filter_preserves_front_and_back_if_needed
# 需要导入模块: from linkedlist import LinkedList [as 别名]
# 或者: from linkedlist.LinkedList import filter [as 别名]
def test_filter_preserves_front_and_back_if_needed(self):
ll = LinkedList()
ll.add_to_front(123, 123123)
ll.add_to_front(234234, 92834923)
ll2 = ll.filter(None)
assert ll.front.key == ll2.front.key
assert ll.front.value == ll2.front.value
assert ll.back.key == ll2.back.key
assert ll.back.value == ll2.back.value
示例4: test_filter_remove_all
# 需要导入模块: from linkedlist import LinkedList [as 别名]
# 或者: from linkedlist.LinkedList import filter [as 别名]
def test_filter_remove_all(self):
ll = LinkedList()
item1 = ll.add_to_front(123, 345)
item2 = ll.add_to_front(51515, 15151551)
item3 = ll.add_to_front(987, 234267)
assert ll.length == 3
assert ll.front == item3
assert ll.back == item1
ll2 = ll.filter(lambda x,y: False)
assert ll2.length == 0
示例5: test_filter_remove_selective
# 需要导入模块: from linkedlist import LinkedList [as 别名]
# 或者: from linkedlist.LinkedList import filter [as 别名]
def test_filter_remove_selective(self):
ll = LinkedList()
item1 = ll.add_to_back(1, 345)
item2 = ll.add_to_back(5, 15151551)
item3 = ll.add_to_back(7, 234267)
item4 = ll.add_to_back(1, 907525)
item5 = ll.add_to_back(7, 789235)
ll2 = ll.filter(lambda x,y: x==1)
assert ll2.length == 2
assert ll2.front.key == item1.key
assert ll2.front.value == item1.value
assert ll2.back.key == item4.key
assert ll2.back.value == item4.value
示例6: test_filter_applies_func_to_all_items
# 需要导入模块: from linkedlist import LinkedList [as 别名]
# 或者: from linkedlist.LinkedList import filter [as 别名]
def test_filter_applies_func_to_all_items(self):
ll = LinkedList()
item1 = ll.add_to_front(123, 345)
item2 = ll.add_to_front("", 2345)
item3 = ll.add_to_front([1,2,3], 234)
ll2 = ll.filter(lambda x, y: True)
ll_current = ll.front
ll2_current = ll2.front
assert ll.length == ll2.length and ll.length == 3
while ll_current:
assert ll_current.key == ll2_current.key
assert ll2_current.value == ll2_current.value
ll_current = ll_current.next
ll2_current = ll2_current.next
示例7: test_filter_creates_new_list
# 需要导入模块: from linkedlist import LinkedList [as 别名]
# 或者: from linkedlist.LinkedList import filter [as 别名]
def test_filter_creates_new_list(self):
ll = LinkedList()
ll2 = ll.filter(None)
assert ll != ll2