I don't understand why these errors appear. TypeError: argument of type 'int' is not iterable

Asked 2 years ago, Updated 2 years ago, 85 views

Let me show you the code first.

arr1 = [1,2,3,3,3,3,4,4]
arr2 = []
arr3 = {1:0,2:0,3:0,4:0}

# 1. Add as a list to the set value arr2 except for the overlapping numbers of arr1
arr2 = list(set(arr1))

a = 0
b = 0
c = 0

# 2. Compare the numbers in arr2 with arr1 and add the number of times to the dictionary in arr3 if they overlap
for a in range(len(arr2)):
    for b in range(len(arr1)):
        if arr2[a] in arr1[b]:
            arr3[a+1] += 1

An error appears in the last to second line, 'if arr2[a] in arr1[b]:'.

    if arr2[a] in arr1[b]:
TypeError: argument of type 'int' is not iterable

I wonder if arr1 and arr2 are not int type anymore, so even if I print it as int type, it shows up as int, but I'm frustrated why this error appears.

typeerror

2022-09-20 15:53

1 Answers

The error message TypeError: argument of type 'int' is not usable is an error caused by the int type (such as list and tuple) where it should be.

There are two variables in the code where the error occurred. The one that should be etherable is the one that is later. In in arr1[b], in must have an (aggregate) enable at the back, and arr1[b] is just one simple int integer.


2022-09-20 15:53

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.