List calculations - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: List calculations (/thread-33026.html) |
List calculations - rturus - Mar-23-2021 Sorry for populating the forum. However, I need some advice. My below data is stored in the lists. I would like to do calculations on the base of the order. For example: T1=Maths[0]+English[1]+History[2]+Acade[3]+Sport[0] This calculation should be done for T2, T3 and T4. I can do with lots of if-elif but I would like to know if there is a better way.
RE: List calculations - deanhystad - Mar-23-2021 Something like this? alist = [[f'{a}{b}' for b in range(4)] for a in 'ABCDE'] for x in alist: print(x) blist = [] count = len(alist[0]) for x in range(count): blist.append([alist[y][(x+y)%count] for y in range(len(alist))]) for x in blist: print(x)What I am calling alist would be [Maths, English, History, Acade, Sport] |