I'm new to Python and I like it, but I was wondering if there is a better way to do a couple of list manipulations.
This is relatively reasonable, but it looks like I might have missed the inline function.
def zip_plus(source_list, additional_list):
"""
Like zip but does plus operation where zip makes a tuple
>>> a = []
>>> zip_plus(a, [[1, 2], [3, 4]])
>>> a
[[1, 2], [3, 4]]
>>> zip_plus(a, [[11, 12], [13, 14]])
>>> a
[[1, 2, 11, 12], [3, 4, 13, 14]]
"""
if source_list:
for i, v in enumerate(additional_list):
source_list[i] += v
else:
source_list.extend(additional_list)
This hoarse and hard to read, any ideas for cleaning it or more pythonic?
def zip_join2(source_list, additional_list):
"""
Pretty gross and specialized function to combine 2 types of lists of things,
specifically a list of tuples of something, list
of which the something is left untouched
>>> a = []
>>> zip_join2(a, [(5, [1, 2]), (6, [3, 4])])
>>> a
[(5, [1, 2]), (6, [3, 4])]
>>> zip_join2(a, [(5, [11, 12]), (6, [13, 14])])
>>> a
[(5, [1, 2, 11, 12]), (6, [3, 4, 13, 14])]
"""
if source_list:
for i, v in enumerate(additional_list):
source_list[i] = (source_list[i][0], source_list[i][1] + v[1])
else:
source_list.extend(additional_list)