MCPcopy Create free account
hub / github.com/FSoft-AI4Code/HyperAgent / concat_strings

Function concat_strings

src/hyperagent/tasks/utils/bl/sequence_utils.py:1–31  ·  view source on GitHub ↗

Concatenates elements from two lists into a new list of strings, combining corresponding elements with a separator. Parameters: list_a (list): The first list containing elements to be combined. list_b (list): The second list containing elements to be combined. sep (

(list_a, list_b, sep=" : ", align=True)

Source from the content-addressed store, hash-verified

1def concat_strings(list_a, list_b, sep=" : ", align=True):
2 """
3 Concatenates elements from two lists into a new list of strings, combining corresponding elements with a separator.
4
5 Parameters:
6 list_a (list): The first list containing elements to be combined.
7 list_b (list): The second list containing elements to be combined.
8 sep (str, optional): The separator to be used between elements. Default is " : ".
9 align (bool, optional): If True, aligns the elements in the output list by padding the first list's elements
10 with spaces to match the width of the longest element. If False, no alignment is applied.
11 Default is True.
12
13 Returns:
14 list of str: A new list of strings combining elements from list_a and list_b.
15
16 Example:
17 list_a = ['1', '2', '33']
18 list_b = ['a', 'b', 'ccc']
19 concat_strings(list_a, list_b, sep=" : ", align=True)
20 Output: [' 1 : a', ' 2 : b', '33 : ccc']
21 """
22 assert len(list_a) == len(list_b), "Input sequences should have the same length"
23 str_list_a = list(map(str, list_a))
24 str_list_b = list(map(str, list_b))
25 if align:
26 max_width_a = max(map(len, str_list_a))
27 return [f"{s_a:>{max_width_a}}{sep}{s_b}"
28 for s_a, s_b in zip(str_list_a, str_list_b)]
29 else:
30 return [f"{s_a}{sep}{s_b}"
31 for s_a, s_b in zip(str_list_a, str_list_b)]
32
33def repeated_subsequences(sequence, min_repetition=5, prefix=None):
34 """

Callers

nothing calls this directly

Calls 1

listFunction · 0.85

Tested by

no test coverage detected