'Got error as TypeError: 'list' object is not callable

for line in sys.stdin:
    myList= list(line.split("|"))
    temp=list(myList(0).split(" "))
    list1=()
    list2=()
    newList=()
    for ele in temp:
        if ele.strip():
            list1.append(ele)
    temp=list(mylist(1).split(" "))
    for ele in temp:
        if ele.strip():
            list2.append(ele.strip())
    count=0
    for count in range (len(list1)):      
        newList.append(int(list1(count))*int(list2(count)))
        count=count+1
    print(newList)

I am trying to print the multiplied list.

Test 1 Input 9 0 6 | 15 14 9 Expected Output 135 0 54

Test 2 13 4 15 1 15 5 | 1 4 15 14 8 2 Expected Output 13 16 225 14 120 10



Solution 1:[1]

Access list elements by index, so change the mylist(1) to mylist[1]
And i fixed your code like this


import sys

for line in sys.stdin:
    myList = line.split("|")
    list1, list2, newList = [], [], []

    for ele in myList[0].split(" "):
        if ele.strip():
            list1.append(ele)

    for ele in myList[1].split(" "):
        if ele.strip():
            list2.append(ele.strip())

    for index in range(len(list1)):
        newList.append(int(list1[index]) * int(list2[index]))
    print(" ".join(str(i) for i in newList))

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1