It's always a bit difficult to answer when there is no reproducible code (e.g. not knowing what source_stream_offset
is, or where varint
comes from, but I think this should apply in general:
- Instead of appending you can use an empty string or byte to
join
individual parts
- You can map over the function rather than using an explicit value
That should yield something like:
bytearray(b''.join(map(varint.encode, source_stream_offset)))
Note: If you're not comfortable with the map
syntax, you can also use a list comprehension like:
bytearray(b''.join([varint.encode(x) for x in source_stream_offset]))