-2
infile=open("Integers.txt", "r")
ListIntegers=infile.readline().strip("\n").split(";")
def avgFirstThreeDigits(mylist):
    list=[]
    for i in range(0,len(mylist)):
        sumFirstThreeDigits=(int(mylist[i][0])+int(mylist[i][1])+int(mylist[i][2]))
        avg=sumFirstThreeDigits/3
        list.append(avg)
    print(list[::-1])
avgFirstThreeDigits(ListIntegers)
Dan D.
  • 73,243
  • 15
  • 104
  • 123
Atakan Ak
  • 11
  • 2

2 Answers2

1

You can manually reverse a list with the following:

a = ['a', 'b', 'c', 'd']
b = [a[len(a) - i - 1] for i in range(len(a))]

>>> b
>>> ['d', 'c', 'b', 'a']
Jeff Mandell
  • 863
  • 7
  • 16
0

If you just want to get a list of tuples/vectors averages, you can just do something like this:

list_averages = [(sum(v3) / len(v3)) for v3 in list_integers]

Or just using another of the multiple ways to calculate the arithmetic mean average will do

About an alternative to [::-1], you can just use list.reverse

But be aware list.reverse will modify in place, if you don't want to you could use list(reversed(list_averages)). In any case, I don't know why you don't want to use [::-1], that one is a pretty fast choice.

Community
  • 1
  • 1
BPL
  • 9,632
  • 9
  • 59
  • 117