I have an array holding another object items :
myarray=[]
myarray.append((1,2,3))
myarray.append((4,5,6))
how can I apply a map function to the last 2 columns of the list somethign like
def inc(x):
return x+1
then
myarray map (inc) # only to the last 2 columns (2,3) and (5,6)
in short I want to transform the data structure from
((1,2,3))
((4,5,6))
to
((1,3,4))
((4,6,7))
thanks
EDIT: just so others can benfit from this I wrote to functions based on @alef response
def format_sub_list(_list,i):
return [[y if i < len(x)-i else inc(y)
for i, y in enumerate(x)]
for x in _list]
or
def format_sub_list2(_list,sublist):
return [[y if i in (sublist) else inc(y)
for i, y in enumerate(x)]
for x in _list]
incor shall it also contain the values which have not been given toinc?