A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z | AA | AB | AC | AD | AE | AF | AG | AH | AI | AJ | AK | AL | AM | AN | AO | AP | AQ | AR | AS | AT | ||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | The link content (in column E) that the participant provided... (check all that apply) | The snippit (in column L) that the participant provided... (check all that apply) | The participant's proposed fix (in column J)... (check all that apply) | ||||||||||||||||||||||||||||||||||||||||||||
2 | Participant | Stimulus ID | Error Prompt | Error Message | SO Link | No link provided | SO link explains a possible cause, directly provides a solution, or explains how to fix the error in error message (not program-specific) | SO link explains a possible cause, directly provides a solution, or explains how to fix the error in error message (program-specific) | SO link proposes an alternative approach to achieve the desired code functionality | SO link explains the cause, provides a solution, or is helpful for a different error in the program prompt than the one in the error message | General Python Knowledge related to the program | Link is not relevent to debugging the program | SO Text/Code Snippet | Source on page | SO snippit blank or not directly copied from SO link | SO snippet explains a possible cause, directly provides a solution, or explains how to fix the error in error message (not program-specific) | SO snippet explains a possible cause, directly provides a solution, or explains how to fix the error in error message (program-specific) | SO snippit proposes an alternative approach to achieve the desired code functionality | SO snippit explains the cause, provides a solution, or is helpful for a different program error than the one in the error message | SO snippit gives debugging advice | SO snippit shows example of correct code or structure relevent to the bug | Specific SO snippit not relevant for debugging the program | Proposed Fix | Blank | Correctly resolves the error indicated by the error message (without introducing new bugs) | Does NOT resolve the error presented in the question | Does not resolve error message, but on the right track / points out the cause | Resolves other errors that are not implicated in the error message | On the right track for other errors that are not implicated in the error message | Resolves error in question, but changes intended program functionality to do so | Resolves error in question, but would produce a new error (that did not already exist in the code) as a result of the proposed change | Extra stuff that is wrong | |||||||||||||||
3 | 1 | 0 | https://drive.google.com/file/d/1GkSTw4zmeZVpm-3C5lkUy96q2OhA8aIx/view?usp=sharing | https://drive.google.com/file/d/10rBxWdNkmnE9bmWps7ITaiZOB0C-A3s5/view?usp=sharing | N/A | N/A | There is missing colon at the end of the for statement | ||||||||||||||||||||||||||||||||||||||||
4 | 9 | 0 | https://drive.google.com/file/d/1GkSTw4zmeZVpm-3C5lkUy96q2OhA8aIx/view?usp=sharing | https://drive.google.com/file/d/10rBxWdNkmnE9bmWps7ITaiZOB0C-A3s5/view?usp=sharing | |||||||||||||||||||||||||||||||||||||||||||
5 | 13 | 0 | https://drive.google.com/file/d/1GkSTw4zmeZVpm-3C5lkUy96q2OhA8aIx/view?usp=sharing | https://drive.google.com/file/d/10rBxWdNkmnE9bmWps7ITaiZOB0C-A3s5/view?usp=sharing | https://stackoverflow.com/questions/42819041/range-function-syntax-error | for i in range(5): | question | for w in range(9): | |||||||||||||||||||||||||||||||||||||||
6 | 15 | 0 | https://drive.google.com/file/d/1GkSTw4zmeZVpm-3C5lkUy96q2OhA8aIx/view?usp=sharing | https://drive.google.com/file/d/10rBxWdNkmnE9bmWps7ITaiZOB0C-A3s5/view?usp=sharing | https://stackoverflow.com/questions/27705523/syntax-error-in-a-for-loop-in-python | The syntax is: for j in range(row): | second answer | colon | |||||||||||||||||||||||||||||||||||||||
7 | 19 | 0 | https://drive.google.com/file/d/1GkSTw4zmeZVpm-3C5lkUy96q2OhA8aIx/view?usp=sharing | https://drive.google.com/file/d/10rBxWdNkmnE9bmWps7ITaiZOB0C-A3s5/view?usp=sharing | https://stackoverflow.com/questions/27705523/syntax-error-in-a-for-loop-in-python | The syntax is: for j in range(row): | second answer | add a colon after range(9) | |||||||||||||||||||||||||||||||||||||||
8 | 22 | 0 | https://drive.google.com/file/d/1GkSTw4zmeZVpm-3C5lkUy96q2OhA8aIx/view?usp=sharing | https://drive.google.com/file/d/10rBxWdNkmnE9bmWps7ITaiZOB0C-A3s5/view?usp=sharing | https://stackoverflow.com/questions/27095402/syntax-error-in-for-loop | You have problems with indentation and colons. Specifically, each for statement needs a colon at the end, just before the following indented block of code. | top answer | for w in range(9): | |||||||||||||||||||||||||||||||||||||||
9 | 24 | 0 | https://drive.google.com/file/d/1GkSTw4zmeZVpm-3C5lkUy96q2OhA8aIx/view?usp=sharing | https://drive.google.com/file/d/10rBxWdNkmnE9bmWps7ITaiZOB0C-A3s5/view?usp=sharing | https://stackoverflow.com/questions/4170656/for-loop-in-python | I can do this for k in range(1,c): In Python, which would be identical to for(int k = 1; k <= c ; k++) | question | They forgot the : sign after the for loop | |||||||||||||||||||||||||||||||||||||||
10 | 30 | 0 | https://drive.google.com/file/d/1GkSTw4zmeZVpm-3C5lkUy96q2OhA8aIx/view?usp=sharing | https://drive.google.com/file/d/10rBxWdNkmnE9bmWps7ITaiZOB0C-A3s5/view?usp=sharing | could not find | n/a | for w in range(9): | ||||||||||||||||||||||||||||||||||||||||
11 | 31 | 0 | https://drive.google.com/file/d/1GkSTw4zmeZVpm-3C5lkUy96q2OhA8aIx/view?usp=sharing | https://drive.google.com/file/d/10rBxWdNkmnE9bmWps7ITaiZOB0C-A3s5/view?usp=sharing | https://stackoverflow.com/questions/39935281/safely-using-for-loop-variables-outside-the-loop | I like to make it a habit of declaring all variables that will be used outside upfront (e.g., setting all variables to None or some other default at the beginning of a function), but it just comes down to preference | top answer | ||||||||||||||||||||||||||||||||||||||||
12 | 35 | 0 | https://drive.google.com/file/d/1GkSTw4zmeZVpm-3C5lkUy96q2OhA8aIx/view?usp=sharing | https://drive.google.com/file/d/10rBxWdNkmnE9bmWps7ITaiZOB0C-A3s5/view?usp=sharing | https://stackoverflow.com/questions/47774358/python3-error-with-colon-in-if-statement/47774771 | is missing a ":" | top/accepted | Forgot colon after first line of for ... for w in range(9): ... | |||||||||||||||||||||||||||||||||||||||
13 | 36 | 0 | https://drive.google.com/file/d/1GkSTw4zmeZVpm-3C5lkUy96q2OhA8aIx/view?usp=sharing | https://drive.google.com/file/d/10rBxWdNkmnE9bmWps7ITaiZOB0C-A3s5/view?usp=sharing | https://stackoverflow.com/questions/85190/how-does-the-java-for-each-loop-work | he construct for each is also valid for arrays. e.g. String[] fruits = new String[] { "Orange", "Apple", "Pear", "Strawberry" }; for (String fruit : fruits) { // fruit is an element of the `fruits` array. } | other answer | There should be ":" after range(9) | |||||||||||||||||||||||||||||||||||||||
14 | 5 | 1 | https://drive.google.com/file/d/14cYoLA8_8Fh1I4-P-MMjfjKszCLPdoSH/view?usp=sharing | https://drive.google.com/file/d/1ox4QFnAdeC49PUK--rfeKMDFiqhrm-j4/view?usp=sharing | https://stackoverflow.com/questions/11621740/how-to-determine-whether-a-year-is-a-leap-year | def leapyr(n): if n%4==0 and n%100!=0: if n%400==0: | question | "def calculate_leapyear(years): print(""year = "", years) if (((years %4) == 0) && ((years %100) != 0)): if (years %400) == 0): print(""The year is a leap year."") else: print(""The year is not a leap year."") return years setup()" | |||||||||||||||||||||||||||||||||||||||
15 | 10 | 1 | https://drive.google.com/file/d/14cYoLA8_8Fh1I4-P-MMjfjKszCLPdoSH/view?usp=sharing | https://drive.google.com/file/d/1ox4QFnAdeC49PUK--rfeKMDFiqhrm-j4/view?usp=sharing | https://stackoverflow.com/questions/11890095/invalid-syntax-error-in-python https://stackoverflow.com/questions/34689390/python-def-function-invalid-syntax https://stackoverflow.com/questions/37283081/python-function-defining-invalid-syntax | Most of these articles are discussing other syntax errors before the passed definition. Google at least is hiding any that forgot the colon on first pass through the results listing. But, all of the results have correct function definitions with colons after them. Hopefully they'd notice theirs didn't. :-) | Just needs a colon: line 4 -- def calculate_leapyear(years): | ||||||||||||||||||||||||||||||||||||||||
16 | 12 | 1 | https://drive.google.com/file/d/14cYoLA8_8Fh1I4-P-MMjfjKszCLPdoSH/view?usp=sharing | https://drive.google.com/file/d/1ox4QFnAdeC49PUK--rfeKMDFiqhrm-j4/view?usp=sharing | https://stackoverflow.com/a/60440375 | def is used to define a function. Normally the code should look like: def getEntry(player, entries): # Do stuff here | top answer | def calculate_leapyear(years): | |||||||||||||||||||||||||||||||||||||||
17 | 14 | 1 | https://drive.google.com/file/d/14cYoLA8_8Fh1I4-P-MMjfjKszCLPdoSH/view?usp=sharing | https://drive.google.com/file/d/1ox4QFnAdeC49PUK--rfeKMDFiqhrm-j4/view?usp=sharing | https://stackoverflow.com/questions/18650313/python3-why-is-this-syntax-invalid | You need a colon after your function definition on line one: def main(): | top answer | Function definition should follow a new scope with colon. def calculate_leapyear(years): | |||||||||||||||||||||||||||||||||||||||
18 | 15 | 1 | https://drive.google.com/file/d/14cYoLA8_8Fh1I4-P-MMjfjKszCLPdoSH/view?usp=sharing | https://drive.google.com/file/d/1ox4QFnAdeC49PUK--rfeKMDFiqhrm-j4/view?usp=sharing | https://stackoverflow.com/questions/11890095/invalid-syntax-error-in-python | def function(x): return x+2; function(2) | top answer | colon | |||||||||||||||||||||||||||||||||||||||
19 | 20 | 1 | https://drive.google.com/file/d/14cYoLA8_8Fh1I4-P-MMjfjKszCLPdoSH/view?usp=sharing | https://drive.google.com/file/d/1ox4QFnAdeC49PUK--rfeKMDFiqhrm-j4/view?usp=sharing | # I didn't find a straight answer for it, but the following link helps https://stackoverflow.com/questions/51072613/syntax-error-when-defining-a-function-on-the-python-command-line | # this code snippet reminds me about the colon def hello(): print ("Hello!") hello() | other answer | def calculate_leapyers(years): .... Same as before ... | |||||||||||||||||||||||||||||||||||||||
20 | 21 | 1 | https://drive.google.com/file/d/14cYoLA8_8Fh1I4-P-MMjfjKszCLPdoSH/view?usp=sharing | https://drive.google.com/file/d/1ox4QFnAdeC49PUK--rfeKMDFiqhrm-j4/view?usp=sharing | https://stackoverflow.com/questions/11890095/invalid-syntax-error-in-python | You need to separate the function definition from its execution. Also, Python is sensitive to whitespace at the beginning of lines. Try this (exactly): def function(x): return x+2 function(2) | top answer | Add a colon to the end of line 4. | |||||||||||||||||||||||||||||||||||||||
21 | 27 | 1 | https://drive.google.com/file/d/14cYoLA8_8Fh1I4-P-MMjfjKszCLPdoSH/view?usp=sharing | https://drive.google.com/file/d/1ox4QFnAdeC49PUK--rfeKMDFiqhrm-j4/view?usp=sharing | https://stackoverflow.com/questions/12722767/how-to-correctly-define-a-function | def count_letters(word): return count_vowels(word) + count_consonants(word) | top/accepted | The function declaration is missing a colon. | |||||||||||||||||||||||||||||||||||||||
22 | 29 | 1 | https://drive.google.com/file/d/14cYoLA8_8Fh1I4-P-MMjfjKszCLPdoSH/view?usp=sharing | https://drive.google.com/file/d/1ox4QFnAdeC49PUK--rfeKMDFiqhrm-j4/view?usp=sharing | n/a | n/a | line 4 is missing a ":", after noticing different 'def', they commonly use a ":" after naming the method. | ||||||||||||||||||||||||||||||||||||||||
23 | 32 | 1 | https://drive.google.com/file/d/14cYoLA8_8Fh1I4-P-MMjfjKszCLPdoSH/view?usp=sharing | https://drive.google.com/file/d/1ox4QFnAdeC49PUK--rfeKMDFiqhrm-j4/view?usp=sharing | https://stackoverflow.com/questions/24237111/syntax-error-invalid-syntax-for-no-apparent-reason | For problems where it seems to be an error on a line you think is correct, you can often remove/comment the line where the error appears to be and, if the error moves to the next line, there are two possibilities. Either both lines have a problem or the previous line has a problem which is being carried forward. The most likely case is the second option (even more so if you remove another line and it moves again). | top/accepted | Add a colon at the end of line 4. Also indent lines 5-13 one to the left. | |||||||||||||||||||||||||||||||||||||||
24 | 34 | 1 | https://drive.google.com/file/d/14cYoLA8_8Fh1I4-P-MMjfjKszCLPdoSH/view?usp=sharing | https://drive.google.com/file/d/1ox4QFnAdeC49PUK--rfeKMDFiqhrm-j4/view?usp=sharing | https://stackoverflow.com/questions/15235024/syntax-error-on-function-declaration-in-python | def __init__(self): | question | def calculate_leapyear(years): | |||||||||||||||||||||||||||||||||||||||
25 | 6 | 2 | https://drive.google.com/file/d/1-ZAhncs4A9w9cmGPJQyz_k4FbMwGK5OF/view?usp=sharing | https://drive.google.com/file/d/1Qd62vF4tMhemAmksMZ4jP24nLj7Bhmp_/view?usp=sharing | https://stackoverflow.com/questions/24237111/syntax-error-invalid-syntax-for-no-apparent-reason | For problems where it seems to be an error on a line you think is correct, you can often remove/comment the line where the error appears to be and, if the error moves to the next line, there are two possibilities. Either both lines have a problem or the previous line has a problem which is being carried forward. The most likely case is the second option (even more so if you remove another line and it moves again). | top/accepted | Fix the first line - add " before "state". 2nd line needs a comma, or "".format() | |||||||||||||||||||||||||||||||||||||||
26 | 7 | 2 | https://drive.google.com/file/d/1-ZAhncs4A9w9cmGPJQyz_k4FbMwGK5OF/view?usp=sharing | https://drive.google.com/file/d/1Qd62vF4tMhemAmksMZ4jP24nLj7Bhmp_/view?usp=sharing | https://stackoverflow.com/questions/18348717/how-to-use-concatenate-a-fixed-string-and-a-variable-in-python | msg['Subject'] = "Auto Hella Restart Report " + sys.argv[1] # To concatenate strings in python, use ^ | top/accepted | There needs to be a "+" between "hello" and name print("hello" + name) | |||||||||||||||||||||||||||||||||||||||
27 | 12 | 2 | https://drive.google.com/file/d/1-ZAhncs4A9w9cmGPJQyz_k4FbMwGK5OF/view?usp=sharing | https://drive.google.com/file/d/1Qd62vF4tMhemAmksMZ4jP24nLj7Bhmp_/view?usp=sharing | https://stackoverflow.com/a/40296837 | name = input("What's your name? ") | top/accepted | This gives some examples at last showing that we need to have open and closed quotations. name=input("state yuor name cuz") | |||||||||||||||||||||||||||||||||||||||
28 | 13 | 2 | https://drive.google.com/file/d/1-ZAhncs4A9w9cmGPJQyz_k4FbMwGK5OF/view?usp=sharing | https://drive.google.com/file/d/1Qd62vF4tMhemAmksMZ4jP24nLj7Bhmp_/view?usp=sharing | https://stackoverflow.com/questions/2589309/command-line-input-causes-syntaxerror | input("Please enter a phone number: ") | question | Ensure quotes are properly used in the input block | |||||||||||||||||||||||||||||||||||||||
29 | 18 | 2 | https://drive.google.com/file/d/1-ZAhncs4A9w9cmGPJQyz_k4FbMwGK5OF/view?usp=sharing | https://drive.google.com/file/d/1Qd62vF4tMhemAmksMZ4jP24nLj7Bhmp_/view?usp=sharing | I couldn't find anything on stack overflow that was directly linked to this issue. I feel like this issue was so simple that stack overflow couldn't be of much use. | N/A | name=input("state yuor name cuz") | ||||||||||||||||||||||||||||||||||||||||
30 | 23 | 2 | https://drive.google.com/file/d/1-ZAhncs4A9w9cmGPJQyz_k4FbMwGK5OF/view?usp=sharing | https://drive.google.com/file/d/1Qd62vF4tMhemAmksMZ4jP24nLj7Bhmp_/view?usp=sharing | https://stackoverflow.com/questions/58463606/how-do-you-format-user-input-as-an-f-string-in-python | message = input('Enter your message: ') | question,top answer | There needs to be " before after the first ( ex: ("state...") | |||||||||||||||||||||||||||||||||||||||
31 | 26 | 2 | https://drive.google.com/file/d/1-ZAhncs4A9w9cmGPJQyz_k4FbMwGK5OF/view?usp=sharing | https://drive.google.com/file/d/1Qd62vF4tMhemAmksMZ4jP24nLj7Bhmp_/view?usp=sharing | https://stackoverflow.com/questions/50437484/syntaxerror-on-input-supposedly-in-python-3 | input takes input from the user and then "executes" or "compiles" it so if you enter 4+9 in the input it will produce the number 13. Not the string "4+9" | other answer | name=input("state yuor name cuz") | |||||||||||||||||||||||||||||||||||||||
32 | 32 | 2 | https://drive.google.com/file/d/1-ZAhncs4A9w9cmGPJQyz_k4FbMwGK5OF/view?usp=sharing | https://drive.google.com/file/d/1Qd62vF4tMhemAmksMZ4jP24nLj7Bhmp_/view?usp=sharing | https://stackoverflow.com/questions/24237111/syntax-error-invalid-syntax-for-no-apparent-reason | # open parentheses: 1 2 3 # v v v fi2=0.460*scipy.sqrt(1-(Tr-0.566)**2/(0.434**2)+0.494 # ^ ^ # close parentheses: 1 2 | top/accepted | name = input ("state your name cuz") print("hello" + name) | |||||||||||||||||||||||||||||||||||||||
33 | 37 | 2 | https://drive.google.com/file/d/1-ZAhncs4A9w9cmGPJQyz_k4FbMwGK5OF/view?usp=sharing | https://drive.google.com/file/d/1Qd62vF4tMhemAmksMZ4jP24nLj7Bhmp_/view?usp=sharing | https://stackoverflow.com/questions/19986096/invalid-syntax-error-when-using-print/19986114 | print("Hello how old are you?(years)") # <== missing this ) You're next syntax errors will probably be the following: c=input() # <== missing () if int(c)==1: # <== missing : print ("") # missing indentation | top answer | As the stack overflow response suggests, the invalid syntax comes from missing something that python expects to see when using the input() function. In this case, name=input(state yuor name cuz") is missing a " and should be corrected to name=input("state yuor name cuz") | |||||||||||||||||||||||||||||||||||||||
34 | 38 | 2 | https://drive.google.com/file/d/1-ZAhncs4A9w9cmGPJQyz_k4FbMwGK5OF/view?usp=sharing | https://drive.google.com/file/d/1Qd62vF4tMhemAmksMZ4jP24nLj7Bhmp_/view?usp=sharing | https://stackoverflow.com/questions/53195935/invalid-syntax-error-when-linking-user-input-to-run-a-set-functionpython | CelsiusorFarenheit = input("Would you like Celsius to Farenheit or Farenheit to Celcius?") This link has an example of how input should be used | question,top answer | name=input("state yuor name cuz") | |||||||||||||||||||||||||||||||||||||||
35 | 39 | 2 | https://drive.google.com/file/d/1-ZAhncs4A9w9cmGPJQyz_k4FbMwGK5OF/view?usp=sharing | https://drive.google.com/file/d/1Qd62vF4tMhemAmksMZ4jP24nLj7Bhmp_/view?usp=sharing | https://stackoverflow.com/questions/2589309/command-line-input-causes-syntaxerror | (Second answer) The code snippet: input("Please enter a phone number: ") | other answer | name=input("state yuor name cuz") | |||||||||||||||||||||||||||||||||||||||
36 | 2 | 3 | https://drive.google.com/file/d/1x0rpLb2XQWKMvPbB_X4Ff-p0jSKn4kGV/view?usp=sharing | https://drive.google.com/file/d/1qbI4STen8i4Ku7VBUIpxHfb5nmd-E6pR/view?usp=sharing | "https://stackoverflow.com/questions/5964927/syntaxerror-cant-assign-to-function-call https://stackoverflow.com/questions/15719172/overload-operator-in-python https://stackoverflow.com/questions/31087111/typeerror-list-object-is-not-callable-in-python" | Answers indicate that function call can't be on the left side of an assignment. That's how I "spotted" my syntax error. But that got me wondering about whether lists can be callable. --- You can make an object callable by implementing the __call__ method --- From title: 'list' object is not callable in python | title,top/accepted | Line 3: b[1] = 999 | |||||||||||||||||||||||||||||||||||||||
37 | 3 | 3 | https://drive.google.com/file/d/1x0rpLb2XQWKMvPbB_X4Ff-p0jSKn4kGV/view?usp=sharing | https://drive.google.com/file/d/1qbI4STen8i4Ku7VBUIpxHfb5nmd-E6pR/view?usp=sharing | https://stackoverflow.com/questions/29615710/syntaxerrorcant-assign-to-function-call | The top answer: To write to a dict, use square brackets: counts[email] = ... instead of counts(email) = ... Round brackets () are used to call a function, so the interpreter thinks you are trying assign a value to a function call. | top/accepted | The programmer has confused the array access syntax `[x]` with the function call syntax `(x)`. By using parentheses rather than square brackets, `b` is treated as if it were a `Callable`, rather than an indexable object, such as, in this case, a list. Fix: b[1] = 999 | |||||||||||||||||||||||||||||||||||||||
38 | 4 | 3 | https://drive.google.com/file/d/1x0rpLb2XQWKMvPbB_X4Ff-p0jSKn4kGV/view?usp=sharing | https://drive.google.com/file/d/1qbI4STen8i4Ku7VBUIpxHfb5nmd-E6pR/view?usp=sharing | https://stackoverflow.com/questions/42534823/syntaxerror-cant-assign-to-function-call/42534892 | stat['minimum'] not stat('minimum') – MooingRawr Mar 1 '17 at 14:50 I have resolved. It's stupid. Adding to a dictionary is: stat['minimum']=data.min() Not stat('minimum')=data.min() – phanindravarma Mar 1 '17 at 14:57 | comment | it needs to be b[1] not b(1) | |||||||||||||||||||||||||||||||||||||||
39 | 16 | 3 | https://drive.google.com/file/d/1x0rpLb2XQWKMvPbB_X4Ff-p0jSKn4kGV/view?usp=sharing | https://drive.google.com/file/d/1qbI4STen8i4Ku7VBUIpxHfb5nmd-E6pR/view?usp=sharing | https://stackoverflow.com/questions/42534823/syntaxerror-cant-assign-to-function-call/42534892 | stat['minimum'] not stat('minimum') | comment | b(1) is an attempted function invocation, not indexing, which it seems like they were attempting to do here. Additionally, tuples are not mutable, so that assignment after moving to b[1] will also fail. They'll need to move a = (1,2,3,4) to a = [1,2,3,4] for that to work. | |||||||||||||||||||||||||||||||||||||||
40 | 17 | 3 | https://drive.google.com/file/d/1x0rpLb2XQWKMvPbB_X4Ff-p0jSKn4kGV/view?usp=sharing | https://drive.google.com/file/d/1qbI4STen8i4Ku7VBUIpxHfb5nmd-E6pR/view?usp=sharing | https://stackoverflow.com/questions/42534823/syntaxerror-cant-assign-to-function-call/42534892 | def statistics(data): stat={} stat['minimum']=data.min() stat["maximum"]=data.max() stat["mean"]=data.mean() stat["median"]=data.median() stat["std"]=data.std() return stat room_stat=statistics(data['RM']) print room_stat | top/accepted | a = (1, 2, 3, 4) b = list(a) b[1] = 999 print (b) | |||||||||||||||||||||||||||||||||||||||
41 | 25 | 3 | https://drive.google.com/file/d/1x0rpLb2XQWKMvPbB_X4Ff-p0jSKn4kGV/view?usp=sharing | https://drive.google.com/file/d/1qbI4STen8i4Ku7VBUIpxHfb5nmd-E6pR/view?usp=sharing | https://stackoverflow.com/questions/10613131/how-to-access-list-elements | print(cities[0][0], cities[1][0]) | top answer | a = [1, 2, 3, 4] b = list(a) b[1] = 999 print (b) | |||||||||||||||||||||||||||||||||||||||
42 | 33 | 3 | https://drive.google.com/file/d/1x0rpLb2XQWKMvPbB_X4Ff-p0jSKn4kGV/view?usp=sharing | https://drive.google.com/file/d/1qbI4STen8i4Ku7VBUIpxHfb5nmd-E6pR/view?usp=sharing | https://stackoverflow.com/questions/5544228/assigning-a-value-to-python-list-doesnt-work | chars[0] = 'd' | top/accepted | b[1] = 999 | |||||||||||||||||||||||||||||||||||||||
43 | 35 | 3 | https://drive.google.com/file/d/1x0rpLb2XQWKMvPbB_X4Ff-p0jSKn4kGV/view?usp=sharing | https://drive.google.com/file/d/1qbI4STen8i4Ku7VBUIpxHfb5nmd-E6pR/view?usp=sharing | https://stackoverflow.com/questions/57179955/syntaxerror-cant-assign-to-function-call-in-python | You can't use int(something)= (that's a function call!), just do something= | comment | ... b[1] = 999 ... | |||||||||||||||||||||||||||||||||||||||
44 | 39 | 3 | https://drive.google.com/file/d/1x0rpLb2XQWKMvPbB_X4Ff-p0jSKn4kGV/view?usp=sharing | https://drive.google.com/file/d/1qbI4STen8i4Ku7VBUIpxHfb5nmd-E6pR/view?usp=sharing | https://stackoverflow.com/questions/1514553/how-to-declare-an-array-in-python | # init with values (can contain mixed types) arr = [1, "eels"] # get item by index (can be negative to access end of array) arr = [1, 2, 3, 4, 5, 6] arr[0] # 1 arr[-1] # 6 | other answer | Not sure what this code is trying to accomplish, but I think the solution is to rewrite line 3 to be b[1] = 999; | |||||||||||||||||||||||||||||||||||||||
45 | 40 | 3 | https://drive.google.com/file/d/1x0rpLb2XQWKMvPbB_X4Ff-p0jSKn4kGV/view?usp=sharing | https://drive.google.com/file/d/1qbI4STen8i4Ku7VBUIpxHfb5nmd-E6pR/view?usp=sharing | https://stackoverflow.com/questions/2582138/finding-and-replacing-elements-in-a-list | a= [1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1] >>> for n, i in enumerate(a): ... if i == 1: ... a[n] = 10 ... >>> a [10, 2, 3, 4, 5, 10, 2, 3, 4, 5, 10] | top/accepted | b(1) = 999 should be changed to b[1] = 999 | |||||||||||||||||||||||||||||||||||||||
46 | 7 | 4 | https://drive.google.com/file/d/1Y-qXNY6JhpLFvwNSkC2DJSNsgPfswPgh/view?usp=sharing | https://drive.google.com/file/d/1zdzIyXvl5qgK4j85XsXmiHhXIXBLx6xp/view?usp=sharing | https://stackoverflow.com/questions/34376441/if-not-condition-statement-in-python | if is the statement. not start is the expression, with not being a boolean operator. not returns True if the operand (start here) is considered false. Python considers all objects to be true, unless they are numeric zero, or an empty container, or the None object or the boolean False value. not returns False if start is a true value. See the Truth Value Testing section in the documentation. | top/accepted | Change the ! symbol to the word "not". if not i: | |||||||||||||||||||||||||||||||||||||||
47 | 8 | 4 | https://drive.google.com/file/d/1Y-qXNY6JhpLFvwNSkC2DJSNsgPfswPgh/view?usp=sharing | https://drive.google.com/file/d/1zdzIyXvl5qgK4j85XsXmiHhXIXBLx6xp/view?usp=sharing | https://stackoverflow.com/questions/11387752/am-i-safe-mixing-types-in-a-python-list | The language is fine with you mixing types in a list, but you should know that the Python culture might frown on it. | top/accepted | The fix again depends on what the code is intended to do. I interpreted it as seeing if one of the elements in the list was false (or was equal to 1 which is equivalent). Since the list is all integers, it would be wise to simply add an "(if i == 1) break". If there are intended to be multiple types in the list, then a type check would be wise. | |||||||||||||||||||||||||||||||||||||||
48 | 11 | 4 | https://drive.google.com/file/d/1Y-qXNY6JhpLFvwNSkC2DJSNsgPfswPgh/view?usp=sharing | https://drive.google.com/file/d/1zdzIyXvl5qgK4j85XsXmiHhXIXBLx6xp/view?usp=sharing | "a=[1,2,3,0,3] for i in a: if !=i: break print(i)" | ||||||||||||||||||||||||||||||||||||||||||
49 | 14 | 4 | https://drive.google.com/file/d/1Y-qXNY6JhpLFvwNSkC2DJSNsgPfswPgh/view?usp=sharing | https://drive.google.com/file/d/1zdzIyXvl5qgK4j85XsXmiHhXIXBLx6xp/view?usp=sharing | https://stackoverflow.com/questions/2485466/pythons-equivalent-of-logical-and-in-an-if-statement | Some of the operators you may know from other languages have a different name in Python. The logical operators && and || are actually called and and or. Likewise the logical negation operator ! is called not. | other answer | if not i: | |||||||||||||||||||||||||||||||||||||||
50 | 16 | 4 | https://drive.google.com/file/d/1Y-qXNY6JhpLFvwNSkC2DJSNsgPfswPgh/view?usp=sharing | https://drive.google.com/file/d/1zdzIyXvl5qgK4j85XsXmiHhXIXBLx6xp/view?usp=sharing | n/a | n/a | ! is not the "not" operator in Python. Switch to "not" | ||||||||||||||||||||||||||||||||||||||||
51 | 21 | 4 | https://drive.google.com/file/d/1Y-qXNY6JhpLFvwNSkC2DJSNsgPfswPgh/view?usp=sharing | https://drive.google.com/file/d/1zdzIyXvl5qgK4j85XsXmiHhXIXBLx6xp/view?usp=sharing | https://stackoverflow.com/questions/22209729/what-does-do-mean-in-python | != means "not equal to" and is a logical comparison. Break down the logical expression here: 2 and 1 - 2 != 3 2 and -1 != 3 2 and True True | top/accepted | On line 3, add a "=" between "!" and "i". | |||||||||||||||||||||||||||||||||||||||
52 | 24 | 4 | https://drive.google.com/file/d/1Y-qXNY6JhpLFvwNSkC2DJSNsgPfswPgh/view?usp=sharing | https://drive.google.com/file/d/1zdzIyXvl5qgK4j85XsXmiHhXIXBLx6xp/view?usp=sharing | https://stackoverflow.com/questions/11060506/is-there-a-not-equal-operator-in-python | != | top/accepted | it needs to be !=, and it also needs to have somethin that it is not equal to | |||||||||||||||||||||||||||||||||||||||
53 | 28 | 4 | https://drive.google.com/file/d/1Y-qXNY6JhpLFvwNSkC2DJSNsgPfswPgh/view?usp=sharing | https://drive.google.com/file/d/1zdzIyXvl5qgK4j85XsXmiHhXIXBLx6xp/view?usp=sharing | https://stackoverflow.com/questions/58049776/does-python-have-logical-inversion-mark-like-exclamation-mark-in-java | There is no !-like prefix operator for booleans in Python, for this we use not | top answer | Changing the ! to "not" could would, or changing "for i in a:" to "for i not in a:" might also work. I think that this would work: a=[1,2,3,0,3] if i not in a: break print(i) | |||||||||||||||||||||||||||||||||||||||
54 | 30 | 4 | https://drive.google.com/file/d/1Y-qXNY6JhpLFvwNSkC2DJSNsgPfswPgh/view?usp=sharing | https://drive.google.com/file/d/1zdzIyXvl5qgK4j85XsXmiHhXIXBLx6xp/view?usp=sharing | https://stackoverflow.com/questions/6117733/negation-in-python | The negation operator in Python is not. Therefore just replace your ! with not. | top/accepted | change '!' to 'not' | |||||||||||||||||||||||||||||||||||||||
55 | 31 | 4 | https://drive.google.com/file/d/1Y-qXNY6JhpLFvwNSkC2DJSNsgPfswPgh/view?usp=sharing | https://drive.google.com/file/d/1zdzIyXvl5qgK4j85XsXmiHhXIXBLx6xp/view?usp=sharing | https://stackoverflow.com/questions/16513573/if-var-false/50978588 | var = False if not var: print 'learnt stuff' | top/accepted | Firstly, i is not a boolean. Also, I think it said that you should use "not" instead of "!" | |||||||||||||||||||||||||||||||||||||||
56 | 36 | 4 | https://drive.google.com/file/d/1Y-qXNY6JhpLFvwNSkC2DJSNsgPfswPgh/view?usp=sharing | https://drive.google.com/file/d/1zdzIyXvl5qgK4j85XsXmiHhXIXBLx6xp/view?usp=sharing | https://stackoverflow.com/questions/16749121/what-does-mean-in-python | t has now been removed in Python 3. Use != instead. | top/accepted | used n != i (n number) instead for the if statement. | |||||||||||||||||||||||||||||||||||||||
57 | 37 | 4 | https://drive.google.com/file/d/1Y-qXNY6JhpLFvwNSkC2DJSNsgPfswPgh/view?usp=sharing | https://drive.google.com/file/d/1zdzIyXvl5qgK4j85XsXmiHhXIXBLx6xp/view?usp=sharing | N/A, SyntaxError is too broad of an error message | The given list a is a list of integers, and thus cannot be combined with the ! operator. A fix to this could be changing the items in a to booleans (True and False). | |||||||||||||||||||||||||||||||||||||||||
58 | 7 | 5 | https://drive.google.com/file/d/1hvf7h1hP2_-bIdbqbo9fM3nqJoJlLwzO/view?usp=sharing | https://drive.google.com/file/d/18NgCqB48hWZqyXHNois62rpEE6L-loIw/view?usp=sharing | https://stackoverflow.com/questions/1875676/python-2-6-str-format-and-regular-expressions | ^(w{{3}}\.)?([0-9A-Za-z-]+\.){{1}}{domainName}$'.format(domainName = 'delivery.com') | top/accepted,other answer | There needs to be a parentheses () around the width variable in order for Python to be able to recognize "width" to be a variable that should be replaced in format(). | |||||||||||||||||||||||||||||||||||||||
59 | 8 | 5 | https://drive.google.com/file/d/1hvf7h1hP2_-bIdbqbo9fM3nqJoJlLwzO/view?usp=sharing | https://drive.google.com/file/d/18NgCqB48hWZqyXHNois62rpEE6L-loIw/view?usp=sharing | https://stackoverflow.com/questions/5082452/string-formatting-vs-format-vs-string-literal https://stackoverflow.com/questions/15286401/print-multiple-arguments-in-python/15286409 | #!/usr/bin/python sub1 = "python string!" sub2 = "an arg" sub_a = "i am a %s" % sub1 sub_b = "i am a {0}".format(sub1) sub_c = f"i am a {sub1}" arg_a = "with %(kwarg)s!" % {'kwarg':sub2} arg_b = "with {kwarg}!".format(kwarg=sub2) arg_c = f"with {sub2}!" print(sub_a) # "i am a python string!" print(sub_b) # "i am a python string!" print(sub_c) # "i am a python string!" print(arg_a) # "with an arg!" print(arg_b) # "with an arg!" print(arg_c) # "with an arg!" print("Total score for {} is {}".format(name, score)) | question | For multiple arguments passed to a string, it looks like using something with multiple '{}' would work better. The arguments passed should not be predefined (but the casting is fine). | |||||||||||||||||||||||||||||||||||||||
60 | 13 | 5 | https://drive.google.com/file/d/1hvf7h1hP2_-bIdbqbo9fM3nqJoJlLwzO/view?usp=sharing | https://drive.google.com/file/d/18NgCqB48hWZqyXHNois62rpEE6L-loIw/view?usp=sharing | https://stackoverflow.com/questions/2456148/getting-syntaxerror-for-print-with-keyword-argument-end | print "Building internam Index for %d tile(s) ..." % len(inputTiles), | other answer | width is not an argument of the print or of the format function, therefore I would just print width directly and in a separate statement from result[a]: print('|{:^width}|'.format(str(width))) | |||||||||||||||||||||||||||||||||||||||
61 | 15 | 5 | https://drive.google.com/file/d/1hvf7h1hP2_-bIdbqbo9fM3nqJoJlLwzO/view?usp=sharing | https://drive.google.com/file/d/18NgCqB48hWZqyXHNois62rpEE6L-loIw/view?usp=sharing | https://stackoverflow.com/questions/60968491/invalid-keyword-argument-for-print | In python, print is a function, which means you can't declare or assign values to variables within it. In some functions, you can specify parameters such as encoding="" in the open function where encoding is the keyword. There is no 'z' keyword for the print statement. The last time, it worked because you assigned the variable before the print statement and then printed it. Try to do some basic research before you ask here, as this is not too complicated | other answer | width=width | |||||||||||||||||||||||||||||||||||||||
62 | 16 | 5 | https://drive.google.com/file/d/1hvf7h1hP2_-bIdbqbo9fM3nqJoJlLwzO/view?usp=sharing | https://drive.google.com/file/d/18NgCqB48hWZqyXHNois62rpEE6L-loIw/view?usp=sharing | https://stackoverflow.com/questions/17559242/var-is-an-invalid-keyword-argument-for-this-function-tkinter-and-python | The error is here: v.set(str(var = var - dictionary[number])) I think you're expecting the interpreter to calculate var - dictionary[number]; assign that value into var; and then pass the value of var along to the str() function as the first argument. The first part of that does actually work - the interpreter does calculate var - dictionary[number]. However, instead of putting that value into var, it passes that value along to the str function as an argument named var. Because the string function isn't expecting an argument named var you get the error you've seen. | other answer | width=width, the keyword argument, is in the wrong function. It's getting called in str() and needs to be called in the .format() function. Move it outside by one paren. | |||||||||||||||||||||||||||||||||||||||
63 | 25 | 5 | https://drive.google.com/file/d/1hvf7h1hP2_-bIdbqbo9fM3nqJoJlLwzO/view?usp=sharing | https://drive.google.com/file/d/18NgCqB48hWZqyXHNois62rpEE6L-loIw/view?usp=sharing | https://stackoverflow.com/questions/10160390/pythons-format-function https://stackoverflow.com/questions/7353486/why-str-cant-get-a-second-parameter-when-str-can | print a.format(data) print a.format(year=year, month=month, location=location) | question | Not sure, but I don't think str() can have a second parameter and it might be solved by deleting one of the pare | |||||||||||||||||||||||||||||||||||||||
64 | 26 | 5 | https://drive.google.com/file/d/1hvf7h1hP2_-bIdbqbo9fM3nqJoJlLwzO/view?usp=sharing | https://drive.google.com/file/d/18NgCqB48hWZqyXHNois62rpEE6L-loIw/view?usp=sharing | https://stackoverflow.com/questions/60968491/invalid-keyword-argument-for-print | 0 In python, print is a function, which means you can't declare or assign values to variables within it. In some functions, you can specify parameters such as encoding="" in the open function where encoding is the keyword. There is no 'z' keyword for the print statement. | other answer | for a in range(height): print('|{:^width}|'.format(str(result[a], 'width =' + width))) | |||||||||||||||||||||||||||||||||||||||
65 | 30 | 5 | https://drive.google.com/file/d/1hvf7h1hP2_-bIdbqbo9fM3nqJoJlLwzO/view?usp=sharing | https://drive.google.com/file/d/18NgCqB48hWZqyXHNois62rpEE6L-loIw/view?usp=sharing | https://stackoverflow.com/questions/30109030/how-does-strlist-work/30109108 | The str() function in python is used to turn a value into a string. | other answer | str(result[a]) | |||||||||||||||||||||||||||||||||||||||
66 | 35 | 5 | https://drive.google.com/file/d/1hvf7h1hP2_-bIdbqbo9fM3nqJoJlLwzO/view?usp=sharing | https://drive.google.com/file/d/18NgCqB48hWZqyXHNois62rpEE6L-loIw/view?usp=sharing | https://stackoverflow.com/questions/17559242/var-is-an-invalid-keyword-argument-for-this-function-tkinter-and-python | str function in python doesn't have var keyword argument. | comment | for a in range(height): print('|{:^width}|'.format(str(result[a]), str(width))) | |||||||||||||||||||||||||||||||||||||||
67 | 39 | 5 | https://drive.google.com/file/d/1hvf7h1hP2_-bIdbqbo9fM3nqJoJlLwzO/view?usp=sharing | https://drive.google.com/file/d/18NgCqB48hWZqyXHNois62rpEE6L-loIw/view?usp=sharing | https://stackoverflow.com/questions/8450472/how-to-print-a-string-at-a-fixed-width | (Second answer): width=10 '{0: <{width}}'.format('sss', width=width) | other answer | print('|{:^width}|'.format(str(result[a]), width = width)) | |||||||||||||||||||||||||||||||||||||||
68 | 40 | 5 | https://drive.google.com/file/d/1hvf7h1hP2_-bIdbqbo9fM3nqJoJlLwzO/view?usp=sharing | https://drive.google.com/file/d/18NgCqB48hWZqyXHNois62rpEE6L-loIw/view?usp=sharing | |||||||||||||||||||||||||||||||||||||||||||
69 | 1 | 6 | https://drive.google.com/file/d/1cDobcbJTUvKSycEu_rdiufDFJ3sN09ql/view?usp=sharing | https://drive.google.com/file/d/1zer1P7MpLNHezpoSfxw0yZ-NPskkvI9E/view?usp=sharing | https://stackoverflow.com/questions/32446402/typeerror-function-object-is-not-subscriptable-in-python-3-4-3 | "'function' object is not subscriptable means you're doing something like this: def foo(): pass something = foo[1] What this means is that either Food_Prices or Food_Stock is actually a function rather than a variable. It should be easy to figure out which, by adding as simple print statement before the line that is causing the error." | top answer | In line 2, the string should be indexed, not the function itself eg. string[0] == string[-1] | |||||||||||||||||||||||||||||||||||||||
70 | 2 | 6 | https://drive.google.com/file/d/1cDobcbJTUvKSycEu_rdiufDFJ3sN09ql/view?usp=sharing | https://drive.google.com/file/d/1zer1P7MpLNHezpoSfxw0yZ-NPskkvI9E/view?usp=sharing | https://stackoverflow.com/questions/32446402/typeerror-function-object-is-not-subscriptable-in-python-3-4-3 | > What this means is that either Food_Prices or Food_Stock is actually a function rather than a variable. | top answer | Line 2: if string[0] == string[-1]: | |||||||||||||||||||||||||||||||||||||||
71 | 4 | 6 | https://drive.google.com/file/d/1cDobcbJTUvKSycEu_rdiufDFJ3sN09ql/view?usp=sharing | https://drive.google.com/file/d/1zer1P7MpLNHezpoSfxw0yZ-NPskkvI9E/view?usp=sharing | https://stackoverflow.com/questions/32446402/typeerror-function-object-is-not-subscriptable-in-python-3-4-3 | function' object is not subscriptable means you're doing something like this: def foo(): pass something = foo[1] What this means is that either Food_Prices or Food_Stock is actually a function rather than a variable | top answer | I think in the if statement you want to index into string that is passed in not into the function. | |||||||||||||||||||||||||||||||||||||||
72 | 6 | 6 | https://drive.google.com/file/d/1cDobcbJTUvKSycEu_rdiufDFJ3sN09ql/view?usp=sharing | https://drive.google.com/file/d/1zer1P7MpLNHezpoSfxw0yZ-NPskkvI9E/view?usp=sharing | https://stackoverflow.com/questions/32446402/typeerror-function-object-is-not-subscriptable-in-python-3-4-3 | What this means is that either Food_Prices or Food_Stock is actually a function rather than a variable. It should be easy to figure out which, by adding as simple print statement before the line that is causing the error. | top answer | if string[0] == string[-1]: | |||||||||||||||||||||||||||||||||||||||
73 | 15 | 6 | https://drive.google.com/file/d/1cDobcbJTUvKSycEu_rdiufDFJ3sN09ql/view?usp=sharing | https://drive.google.com/file/d/1zer1P7MpLNHezpoSfxw0yZ-NPskkvI9E/view?usp=sharing | https://stackoverflow.com/questions/29101836/typeerror-function-object-is-not-subscriptable-python | You have two objects both named bank_holiday -- one a list and one a function. Disambiguate the two. | top answer | string[0] == string[-1] | |||||||||||||||||||||||||||||||||||||||
74 | 17 | 6 | https://drive.google.com/file/d/1cDobcbJTUvKSycEu_rdiufDFJ3sN09ql/view?usp=sharing | https://drive.google.com/file/d/1zer1P7MpLNHezpoSfxw0yZ-NPskkvI9E/view?usp=sharing | https://stackoverflow.com/questions/33380936/typeerror-function-object-is-not-subscriptable | You want to apply [1:] to l, not to sumList (sumList is a function). | top/accepted | def pd(string): if string[0]== string[-1]: return True else: return False pd(string[1:-1]) pd('1221') | |||||||||||||||||||||||||||||||||||||||
75 | 20 | 6 | https://drive.google.com/file/d/1cDobcbJTUvKSycEu_rdiufDFJ3sN09ql/view?usp=sharing | https://drive.google.com/file/d/1zer1P7MpLNHezpoSfxw0yZ-NPskkvI9E/view?usp=sharing | https://stackoverflow.com/questions/32446402/typeerror-function-object-is-not-subscriptable-in-python-3-4-3 | function' object is not subscriptable means you're doing something like this: def foo(): pass something = foo[1] | top answer | if string[0] == string[-1]: ... Same as before ... | |||||||||||||||||||||||||||||||||||||||
76 | 24 | 6 | https://drive.google.com/file/d/1cDobcbJTUvKSycEu_rdiufDFJ3sN09ql/view?usp=sharing | https://drive.google.com/file/d/1zer1P7MpLNHezpoSfxw0yZ-NPskkvI9E/view?usp=sharing | Didn't find it on a site | pd('1221') needs to be earlier, since it tries indexing into something that is undefined, which causes an error. | |||||||||||||||||||||||||||||||||||||||||
77 | 30 | 6 | https://drive.google.com/file/d/1cDobcbJTUvKSycEu_rdiufDFJ3sN09ql/view?usp=sharing | https://drive.google.com/file/d/1zer1P7MpLNHezpoSfxw0yZ-NPskkvI9E/view?usp=sharing | https://stackoverflow.com/questions/29101836/typeerror-function-object-is-not-subscriptable-python | You have two objects both named bank_holiday -- one a list and one a function. Disambiguate the two. bank_holiday[month] is raising an error because Python thinks bank_holiday refers to the function (the last object bound to the name bank_holiday), whereas you probably intend it to mean the list. | top answer | if string[0] == string[-1] | |||||||||||||||||||||||||||||||||||||||
78 | 31 | 6 | https://drive.google.com/file/d/1cDobcbJTUvKSycEu_rdiufDFJ3sN09ql/view?usp=sharing | https://drive.google.com/file/d/1zer1P7MpLNHezpoSfxw0yZ-NPskkvI9E/view?usp=sharing | https://stackoverflow.com/questions/29101836/typeerror-function-object-is-not-subscriptable-python | function' object is not subscriptable means you're doing something like this: def foo(): pass something = foo[1] Most likely this is because you have a function somewhere else in your code named either Food_Prices or Food_Stock, or you've reassigned the value of one of those variables. | top answer | They accidentally indexed the function instead of the string that the function takes in | |||||||||||||||||||||||||||||||||||||||
79 | 36 | 6 | https://drive.google.com/file/d/1cDobcbJTUvKSycEu_rdiufDFJ3sN09ql/view?usp=sharing | https://drive.google.com/file/d/1zer1P7MpLNHezpoSfxw0yZ-NPskkvI9E/view?usp=sharing | https://stackoverflow.com/questions/29101836/typeerror-function-object-is-not-subscriptable-python | bank_holiday[month] is raising an error because Python thinks bank_holiday refers to the function (the last object bound to the name bank_holiday), whereas you probably intend it to mean the list. | top answer | There is a function inside it's own fucntion. Disambiguate pd(string[1:-1]). | |||||||||||||||||||||||||||||||||||||||
80 | 3 | 7 | https://drive.google.com/file/d/19UZCAcsKPrwfg0cBDwiW2hRd6Ysj-gYR/view?usp=sharing | https://drive.google.com/file/d/1txtBDPtRABM0QM3bUvyKb18hJIgXz7Lv/view?usp=sharing | https://stackoverflow.com/questions/5796238/python-convert-decimal-to-hex | I think this solution is elegant: def toHex(dec): x = (dec % 16) digits = "0123456789ABCDEF" rest = dec / 16 if (rest == 0): return digits[x] return toHex(rest) + digits[x] numbers = [0, 11, 16, 32, 33, 41, 45, 678, 574893] print [toHex(x) for x in numbers] print [hex(x) for x in numbers] This output: ['0', 'B', '10', '20', '21', '29', '2D', '2A6', '8C5AD'] ['0x0', '0xb', '0x10', '0x20', '0x21', '0x29', '0x2d', '0x2a6', '0x8c5ad'] | other answer | There's a few issues here. The immediate failure is that `idx` is a string and so it's not indexable. It looks like the programmer meant to do `table[idx]`. For one, the loop variable `idx` in the loop on line 21 is looping over the individual characters, represented as strings, in the input number, `number`. This doesn't really make sense, since the conversion needs to be from base 10 to base 16 -- you can't just lookup each of the digits in a base-10 number to convert it into base 16. Instead, you could the standard library to do this, or, if you want to implement it from scratch you can successively repeat integer divisions / modulo operations. | |||||||||||||||||||||||||||||||||||||||
81 | 9 | 7 | https://drive.google.com/file/d/19UZCAcsKPrwfg0cBDwiW2hRd6Ysj-gYR/view?usp=sharing | https://drive.google.com/file/d/1txtBDPtRABM0QM3bUvyKb18hJIgXz7Lv/view?usp=sharing | https://stackoverflow.com/questions/27312553/python-typeerror-string-indices-must-be-integers-how-to-fix | Either activity or activity['object'] is a string and not a dictionary as you expect. Print data and check. | top answer | Swap idx and table: decToHexConvert += table[idx] | |||||||||||||||||||||||||||||||||||||||
82 | 13 | 7 | https://drive.google.com/file/d/19UZCAcsKPrwfg0cBDwiW2hRd6Ysj-gYR/view?usp=sharing | https://drive.google.com/file/d/1txtBDPtRABM0QM3bUvyKb18hJIgXz7Lv/view?usp=sharing | https://stackoverflow.com/questions/6077675/why-am-i-seeing-typeerror-string-indices-must-be-integers | data is a dict object. So, iterate over it like this: Python 2 for key, value in data.iteritems(): print key, value Python 3 for key, value in data.items(): print(key, value) | other answer | decToHexConvert += table[idx] | |||||||||||||||||||||||||||||||||||||||
83 | 16 | 7 | https://drive.google.com/file/d/19UZCAcsKPrwfg0cBDwiW2hRd6Ysj-gYR/view?usp=sharing | https://drive.google.com/file/d/1txtBDPtRABM0QM3bUvyKb18hJIgXz7Lv/view?usp=sharing | https://stackoverflow.com/questions/40785555/basic-python-misunderstanding-of-dict-typeerror-string-indices-must-be-integer | In your code trying to index string with string instead of dictionary. | top answer | table and idx are flipped here. I assume they were intending to get the value in the table dictionary with the "index" idx variable. | |||||||||||||||||||||||||||||||||||||||
84 | 19 | 7 | https://drive.google.com/file/d/19UZCAcsKPrwfg0cBDwiW2hRd6Ysj-gYR/view?usp=sharing | https://drive.google.com/file/d/1txtBDPtRABM0QM3bUvyKb18hJIgXz7Lv/view?usp=sharing | https://stackoverflow.com/questions/6077675/why-am-i-seeing-typeerror-string-indices-must-be-integers | Strings can't have string indices (like dictionaries can). So this won't work: >>> mystring = 'helloworld' >>> print mystring['stringindex'] TypeError: string indices must be integers | other answer | decToHexConvert += table[idx] instead of idx[table] | |||||||||||||||||||||||||||||||||||||||
85 | 22 | 7 | https://drive.google.com/file/d/19UZCAcsKPrwfg0cBDwiW2hRd6Ysj-gYR/view?usp=sharing | https://drive.google.com/file/d/1txtBDPtRABM0QM3bUvyKb18hJIgXz7Lv/view?usp=sharing | https://stackoverflow.com/questions/6077675/why-am-i-seeing-typeerror-string-indices-must-be-integers | We need to replace the comma , with a colon : | other answer | decToHex(15) | |||||||||||||||||||||||||||||||||||||||
86 | 24 | 7 | https://drive.google.com/file/d/19UZCAcsKPrwfg0cBDwiW2hRd6Ysj-gYR/view?usp=sharing | https://drive.google.com/file/d/1txtBDPtRABM0QM3bUvyKb18hJIgXz7Lv/view?usp=sharing | https://stackoverflow.com/questions/33948354/how-to-get-indexes-of-elements-in-a-table-using-python | T[i] | top/accepted | it should be table[id], not idx[table] | |||||||||||||||||||||||||||||||||||||||
87 | 27 | 7 | https://drive.google.com/file/d/19UZCAcsKPrwfg0cBDwiW2hRd6Ysj-gYR/view?usp=sharing | https://drive.google.com/file/d/1txtBDPtRABM0QM3bUvyKb18hJIgXz7Lv/view?usp=sharing | https://stackoverflow.com/questions/49695836/typeerror-string-indices-must-be-integers-python | data['result'] is a dictionary. Iterating over dict means iterating over its keys. Therefore key variable stores a string. That's why key['id'] raises TypeError: string indices must be integers. | top/accepted | The dec to hex converter needs to take the whole '15' string not by index because 1 and 5 will be converted separately. | |||||||||||||||||||||||||||||||||||||||
88 | 31 | 7 | https://drive.google.com/file/d/19UZCAcsKPrwfg0cBDwiW2hRd6Ysj-gYR/view?usp=sharing | https://drive.google.com/file/d/1txtBDPtRABM0QM3bUvyKb18hJIgXz7Lv/view?usp=sharing | https://stackoverflow.com/questions/6077675/why-am-i-seeing-typeerror-string-indices-must-be-integers | >>> mystring = 'helloworld' >>> print mystring[0] 'h' | other answer | Uh I think there's probably quite a few errors with the code in the sense of getting what the function should get, but in terms of just coding errors, you can't call "idx[table]" because in our case, table is an entire dictionary. For string indices, you need to use numbers (ex: str[0]). | |||||||||||||||||||||||||||||||||||||||
89 | 33 | 7 | https://drive.google.com/file/d/19UZCAcsKPrwfg0cBDwiW2hRd6Ysj-gYR/view?usp=sharing | https://drive.google.com/file/d/1txtBDPtRABM0QM3bUvyKb18hJIgXz7Lv/view?usp=sharing | https://stackoverflow.com/questions/49695836/typeerror-string-indices-must-be-integers-python | Iterating over dict means iterating over its keys. Therefore key variable stores a string. | top/accepted | decToHexConvert += table[idx] on line 22 | |||||||||||||||||||||||||||||||||||||||
90 | 34 | 7 | https://drive.google.com/file/d/19UZCAcsKPrwfg0cBDwiW2hRd6Ysj-gYR/view?usp=sharing | https://drive.google.com/file/d/1txtBDPtRABM0QM3bUvyKb18hJIgXz7Lv/view?usp=sharing | https://stackoverflow.com/questions/6077675/why-am-i-seeing-typeerror-string-indices-must-be-integers | decToHexConvert += table[idx] | |||||||||||||||||||||||||||||||||||||||||
91 | 35 | 7 | https://drive.google.com/file/d/19UZCAcsKPrwfg0cBDwiW2hRd6Ysj-gYR/view?usp=sharing | https://drive.google.com/file/d/1txtBDPtRABM0QM3bUvyKb18hJIgXz7Lv/view?usp=sharing | https://stackoverflow.com/questions/6077675/why-am-i-seeing-typeerror-string-indices-must-be-integers | item is most likely a string in your code; the string indices are the ones in the square brackets, e.g., gravatar_id. So I'd first check your data variable to see what you received there; I guess that data is a list of strings (or at least a list containing at least one string) while it should be a list of dictionaries. | accepted answer | The index can't be a string, so you need to convert the '15' to an integer first then iterate over the dictionary | |||||||||||||||||||||||||||||||||||||||
92 | 38 | 7 | https://drive.google.com/file/d/19UZCAcsKPrwfg0cBDwiW2hRd6Ysj-gYR/view?usp=sharing | https://drive.google.com/file/d/1txtBDPtRABM0QM3bUvyKb18hJIgXz7Lv/view?usp=sharing | https://stackoverflow.com/questions/41836011/typeerror-string-indices-must-be-integers-error-when-parsing-json-with-python | for each in data['items']: print(each['created_on']) | question | decToHexConvert += table[idx] | |||||||||||||||||||||||||||||||||||||||
93 | 7 | 8 | https://drive.google.com/file/d/1McYm9CgMgHWC_vsyVn4VBh1tLaGH-vnT/view?usp=sharing | https://drive.google.com/file/d/1DHzCmI8yeVCX_YvU-3EZoTzClfsSvLvI/view?usp=sharing | https://stackoverflow.com/questions/60504217/typeerror-not-supported-between-instances-of-list-and-int | Error at line while complete < 30. The complete is a list and you try to compare it with a integer number 30? If you want to compare the list length, use while len(complete) < 30. | top answer | The problem here is that the programmer is trying to compare a list to an integer. I believe the programmer meant to initialize smallest to xs[0], rather than the entire xs list. The variable smaller should be initialized to xs[0] as well. | |||||||||||||||||||||||||||||||||||||||
94 | 10 | 8 | https://drive.google.com/file/d/1McYm9CgMgHWC_vsyVn4VBh1tLaGH-vnT/view?usp=sharing | https://drive.google.com/file/d/1DHzCmI8yeVCX_YvU-3EZoTzClfsSvLvI/view?usp=sharing | https://stackoverflow.com/questions/58403569/python-typeerror-not-supported-between-instances-of-int-and-list | "I really think this should be a built-in operation for comparison operators. e.g. 3 < [4,5] should return [True, True] and 3 < [3,4] should return [False, True]" -- OP "@DanGoodrick I disagree. Python is a general purpose programming language that is strongly typed. Comparison operations between distinct types should be an error." -- bystander | comment | def second_smallest(xs): smallest=xs[0] # Here -- previously was assigning an entire list rather than a single index smaller=xs[0] # here -- As above for i in range(len(xs)): # Here, we were creating a new list containing a single element, the value of smaller (which was also itself a list previously). i would at most be 0. if smallest>xs[i]: smaller=smallest smallest=xs[i] # Previously smallest was assigned the current index, not the value at the current index. elif smaller>xs[i] and not smallest==1: #??? smaller=xs[i] # return smaller second_smallest([1,2,3,4]) | |||||||||||||||||||||||||||||||||||||||
95 | 12 | 8 | https://drive.google.com/file/d/1McYm9CgMgHWC_vsyVn4VBh1tLaGH-vnT/view?usp=sharing | https://drive.google.com/file/d/1DHzCmI8yeVCX_YvU-3EZoTzClfsSvLvI/view?usp=sharing | https://stackoverflow.com/questions/55946241/typeerror-not-supported-between-instances-of-list-and-int-python | Hint: try to understand the error message. Which of those is a list and which is an int? Do you want them to be list or int? Why is the type not as you expect? | comment | smallest=xs[0] smaller=xs[0] (technically this does not work if the list is empty) | |||||||||||||||||||||||||||||||||||||||
96 | 17 | 8 | https://drive.google.com/file/d/1McYm9CgMgHWC_vsyVn4VBh1tLaGH-vnT/view?usp=sharing | https://drive.google.com/file/d/1DHzCmI8yeVCX_YvU-3EZoTzClfsSvLvI/view?usp=sharing | https://stackoverflow.com/questions/49472108/typeerror-not-supported-between-instances-of-list-and-int/49472188 | This is the root of all your problems, since now suffix[0] becomes a list after the first iteration through your loop. The biggest change you needed was as follows: | top/accepted | def second_smallest(xs): smallest=xs[0] smaller=XS[0] for i in range(len([smaller])): if smallest>i: smaller=smallest smallest=i elif smaller>i and not smallest==1: smaller=i return smaller second_smallest([1,2,3,4]) | |||||||||||||||||||||||||||||||||||||||
97 | 19 | 8 | https://drive.google.com/file/d/1McYm9CgMgHWC_vsyVn4VBh1tLaGH-vnT/view?usp=sharing | https://drive.google.com/file/d/1DHzCmI8yeVCX_YvU-3EZoTzClfsSvLvI/view?usp=sharing | https://stackoverflow.com/questions/49472108/typeerror-not-supported-between-instances-of-list-and-int/49472188 | You have a lot of issues where you don't distinguish between lists and integers. million = [1000000, "M"] billion = [million * 1000, "B"] billion[0] is not actually a 1000000 * 1000, its a length 1000 list. This is the root of all your problems, since now suffix[0] becomes a list after the first iteration through your loop. The biggest change you needed was as follows: million = [1000000, "M"] billion = [million[0] * 1000, "B"] trillion = [billion[0] * 1000, "T"] quadrillion = [trillion[0] * 1000, "Qd"] quintillion = [quadrillion[0] * 1000, "Qn"] sx = [quintillion[0] * 1000, "Sx"] septillion = [sx[0] * 1000, "Sp"] | top/accepted | use something like this instead of the first two lines in the function: smaller = max(xs[0], xs[1]) smallest = min(xs[0], xs[1]) | |||||||||||||||||||||||||||||||||||||||
98 | 23 | 8 | https://drive.google.com/file/d/1McYm9CgMgHWC_vsyVn4VBh1tLaGH-vnT/view?usp=sharing | https://drive.google.com/file/d/1DHzCmI8yeVCX_YvU-3EZoTzClfsSvLvI/view?usp=sharing | https://stackoverflow.com/questions/60504217/typeerror-not-supported-between-instances-of-list-and-int | Error at line while complete < 30. The complete is a list and you try to compare it with a integer number 30? If you want to compare the list length, use while len(complete) < 30 | top answer | for i in range(len([smaller])) should be rewritten as: for i in len(smaller) | |||||||||||||||||||||||||||||||||||||||
99 | 25 | 8 | https://drive.google.com/file/d/1McYm9CgMgHWC_vsyVn4VBh1tLaGH-vnT/view?usp=sharing | https://drive.google.com/file/d/1DHzCmI8yeVCX_YvU-3EZoTzClfsSvLvI/view?usp=sharing | https://stackoverflow.com/questions/60504217/typeerror-not-supported-between-instances-of-list-and-int | Error at line while complete < 30. The complete is a list and you try to compare it with a integer number 30? | top answer | You have to access the element of the list being inputted. You can do something like if smallest[i] > i:, and the same for the rest of them, rather than just putting smallest | |||||||||||||||||||||||||||||||||||||||
100 | 26 | 8 | https://drive.google.com/file/d/1McYm9CgMgHWC_vsyVn4VBh1tLaGH-vnT/view?usp=sharing | https://drive.google.com/file/d/1DHzCmI8yeVCX_YvU-3EZoTzClfsSvLvI/view?usp=sharing | https://stackoverflow.com/questions/60504217/typeerror-not-supported-between-instances-of-list-and-int | 2 Error at line while complete < 30. The complete is a list and you try to compare it with a integer number 30? If you want to compare the list length, use while len(complete) < 30. | top answer | smallest is set to the list xs so you cannot compare it to i which is an int. Most likely the code wants to compare the i'th element of smallest so if smallest[i] > i Similarly with the elif statement to avoid another error. |