Python Forum

Full Version: List calculations
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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.

Output:
Maths [6, 7, 8, 5] English [9, 9, 8, 7] History [6, 6, 7, 8] Acade [9, 9, 8, 7] Sport [6, 6, 7, 8] ---------------------------------------- T1 T2 T3 T4 order for Maths ['A', 'B', 'C', 'D'] order for English ['B', 'C', 'D', 'A'] order for History ['C', 'D', 'A', 'B'] order for Academic ['D', 'C', 'B', 'A'] order for Sports ['A', 'B', 'C', 'D']
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]