Jan-22-2019, 05:14 PM
Sure can! So we have a base of understanding, here's your current code:
>>> tmp = [ ... [1, 2, 3, 4], ... [5, 6, 7, 8], ... [9, 10, 11, 12] ... ] >>> newList = [] >>> for rec in tmp: ... newList.append([rec[0]*2, rec[1]*2, rec[3]*2]) ... >>> newList [[2, 4, 8], [10, 12, 16], [18, 20, 24]]Here's a list comprehension that does the same:
>>> [[a*2, b*2, d*2] for a,b,c,d in tmp] [[2, 4, 8], [10, 12, 16], [18, 20, 24]]