Type Error: 'generator' object is not subscriptable in python

type 1 error example problems
probability of type 2 error
type 1 and type 2 error practice problems
probability of type 1 error
type error python
type 3 error
how to reduce type 1 error
type 2 error psychology
def activity_select(i):
    list(i)
    i.sort(key=lambda x: x[2])
    n = len(i)                        # set n to length of i 
    solution = []
    print("Following activities are selected ")
    j = 0                             # first activity always selected
    solution.append(i[j][0])
    for k in range(n):                # loop through remainder of activities
        if i[k][1] >= i[k][2]:        # if activity has greater start time
            solution.append(i[k][0]) #
            j = k
            return solution

file = open('act.txt')
st = []
sn = 1
for line in file:
    l = line.rstrip()
    if '' not in l and len(st) > 0:
        print("Set", sn)
        solution = activity_select(st)
        print("Number of activities selected = ", len(solution))
        print("Activities: ", *solution)
        sn += 1
        st = []
else:
            st.append((int(i) for i in l.split()))
if len(st) > 0:
    print("Set ", sn)
    sol = activity_select(st)
    print("Number of activities selected = ", len(sol))
    print("Activities: ", *solution)

However I am getting the following errors

line 27, in <module>
    sol = activity_select(st)
line 9, in activity_select
    sol.append(v[i][0])
TypeError: 'generator' object is not subscriptable 

Is this related to the st variable? Or is it something else?

I see a couple obvious errors here:

  1. You converted your i argument to a list and didn't assign it back to i, so if it's not a list, the function is broken from the start. Use i = list(i) to replace i with the result of listifying
  2. You call st.append((int(i) for i in l.split())) which is calling append with a generator (created via a generator expression). If it's supposed to be a list, use brackets, not parens: st.append([int(i) for i in l.split()]). If each result should be added separately, use extend instead: st.extend(int(i) for i in l.split())

Problem #2 is almost certainly the source of your current error, but fixing #1 is important for making your code usable with non-lists (and to avoid having it mutate the caller's copy of the list even when it works).

Understanding Type I and II Errors - InFocus Blog, , or false positive, is asserting something as true when it is actually false. A type I error is a kind of fault that occurs during the hypothesis testing process when a null hypothesis is rejected, even though it is accurate and should not be rejected. In hypothesis testing

It is hard to debug your code seeing that you are reading of a file we do not have. My guess would be you are trying slice a generator, a quick glance shows that you have a generator expression here:

st.append((int(i) for i in l.split()))

Try changing it to st.append([int(i) for i in l.split()]) to get a nested list.

Examples identifying Type I and Type II errors (video), What is Type I and Type II error give examples? Type I error. The first kind of error is the rejection of a true null hypothesis as the result of a test procedure. This kind of error is called a type I error and is sometimes called an error of the first kind. In terms of the courtroom example, a type I error corresponds to convicting an innocent defendant.

Basically the problem with your code is:

st.append((int(i) for i in l.split()))

because you're appending a generator with is un-indexable, un-sliceable , un-subscriptable , so use a list comprehension which is indexable, sliceable, subscriptable.

So instead of:

st.append((int(i) for i in l.split()))

Do:

st.append([int(i) for i in l.split()])

A Definitive Guide on Types of Error in Statistics, rejects the alternative hypothesis, even though it does not occur due to chance. The first kind of error that is possible involves the rejection of a null hypothesis that is actually true. This kind of error is called a type I error and is sometimes called an error of the first kind. Type I errors are equivalent to false positives. Let’s go back to the example of a drug being used to treat a disease.

Type II Error Definition, Type I and Type II errors. • Type I error, also known as a “false positive”: the error of rejecting a null hypothesis when it is actually true. In other words, this is the  A type 1 error is also known as a false positive and occurs when a researcher incorrectly rejects a true null hypothesis. This means that your report that your findings are significant when in fact they have occurred by chance.

A Type I error occurs when we reject the null hypothesis of a population parameter when the Duration: 5:03 Posted: Feb 25, 2018 Dismiss Grow your team on GitHub. GitHub is home to over 40 million developers working together. Join them to grow your own development teams, manage permissions, and collaborate on projects.

A type I error is a kind of fault that occurs during the hypothesis testing process when a null hypothesis is rejected, even though it is accurate  Your configurationID is None.This likely means that generate_configurationID() is not returning a value. There is no way in Python for a variable name to "lose" its value. The only way, in the code you posted, for configurationID to be None is for generate_configurationID() to return None which is what will happen if you don't explicitly return any val

Comments
  • there's something missing, the exception clearly states that you want to use slice notations in a generator(generator[1]) which is not suported, but i dont see any generators in your code. The reason is because as its name implies generators do not have store the data, they are kind of 'ethereal' as in it generates the data on the fly, theres no data ahead nor behind