pwnlib.util.lists
— Operations on lists¶
-
pwnlib.util.lists.
concat
(l) → list[源代码]¶ Concats a list of lists into a list.
Example
>>> concat([[1, 2], [3]]) [1, 2, 3]
-
pwnlib.util.lists.
concat_all
(*args) → list[源代码]¶ Concats all the arguments together.
Example
>>> concat_all(0, [1, (2, 3)], [([[4, 5, 6]])]) [0, 1, 2, 3, 4, 5, 6]
-
pwnlib.util.lists.
findall
(l, e) → l[源代码]¶ Generate all indices of needle in haystack, using the Knuth-Morris-Pratt algorithm.
Example
>>> foo = findall([1,2,3,4,4,3,4,2,1], 4) >>> foo.next() 3 >>> foo.next() 4 >>> foo.next() 6
-
pwnlib.util.lists.
group
(n, lst, underfull_action = 'ignore', fill_value = None) → list[源代码]¶ Split sequence into subsequences of given size. If the values cannot be evenly distributed among into groups, then the last group will either be returned as is, thrown out or padded with the value specified in fill_value.
参数: 返回: A list containing the grouped values.
Example
>>> group(3, "ABCDEFG") ['ABC', 'DEF', 'G'] >>> group(3, 'ABCDEFG', 'drop') ['ABC', 'DEF'] >>> group(3, 'ABCDEFG', 'fill', 'Z') ['ABC', 'DEF', 'GZZ'] >>> group(3, list('ABCDEFG'), 'fill') [['A', 'B', 'C'], ['D', 'E', 'F'], ['G', None, None]]
-
pwnlib.util.lists.
ordlist
(s) → list[源代码]¶ Turns a string into a list of the corresponding ascii values.
Example
>>> ordlist("hello") [104, 101, 108, 108, 111]
-
pwnlib.util.lists.
partition
(lst, f, save_keys = False) → list[源代码]¶ Partitions an iterable into sublists using a function to specify which group they belong to.
It works by calling f on every element and saving the results into an
collections.OrderedDict
.参数: Example
>>> partition([1,2,3,4,5], lambda x: x&1) [[1, 3, 5], [2, 4]]