pwnlib.util.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.

参数:
  • n (int) – The size of resulting groups
  • lst – The list, tuple or string to group
  • underfull_action (str) – The action to take in case of an underfull group at the end. Possible values are ‘ignore’, ‘drop’ or ‘fill’.
  • fill_value – The value to fill into an underfull remaining group.
返回:

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.

参数:
  • lst – The iterable to partition
  • f (function) – The function to use as the partitioner.
  • save_keys (bool) – Set this to True, if you want the OrderedDict returned instead of just the values

Example

>>> partition([1,2,3,4,5], lambda x: x&1)
[[1, 3, 5], [2, 4]]
pwnlib.util.lists.unordlist(cs) → str[源代码]

Takes a list of ascii values and returns the corresponding string.

Example

>>> unordlist([104, 101, 108, 108, 111])
'hello'