indexoutofboundsexception

Python giving list out of bounds but it shows both elements in the list

Python giving list out of bounds but it shows both elements in the list Question: I’m trying to make a simple log in program using python (still fairly new to it), and I have the log in information stored in a text file for the user to match in order to successfully log in. Whenever …

Total answers: 4

IndexError: list index out of range in python for strings

IndexError: list index out of range in python for strings Question: I wanted to remove the word “hello” from this array, but I get the “index out of bounds” error. I checked the range of len(token); it was (0,5). Here is the code: token=[‘hi’,’hello’,’how’,’are’,’you’] stop=’hello’ for i in range(len(token)): if(token[i]==stop): del(token[i]) Asked By: Chanakya Harish …

Total answers: 6

Python index out of range in list slicing

Python index out of range in list slicing Question: While this code will raise indexError: In [1]: lst = [1, 2, 3] In [2]: lst[3] IndexError: list index out of range Slicing the list with “out of range index” will not produce any error. In [3]: lst[3:] Out[3]: [] What is the rationale of this …

Total answers: 2

Why doesn't list have safe "get" method like dictionary?

Why doesn't list have safe "get" method like dictionary? Question: Why doesn’t list have a safe “get” method like dictionary? >>> d = {‘a’:’b’} >>> d[‘a’] ‘b’ >>> d[‘c’] KeyError: ‘c’ >>> d.get(‘c’, ‘fail’) ‘fail’ >>> l = [1] >>> l[10] IndexError: list index out of range Asked By: Mikhail M. || Source Answers: Ultimately …

Total answers: 13