It looks like you are using Python 3.x. One of the important differences in Python 3.x is the way division is handled. When you do x / y
, an integer is returned in Python 2.x because the decimal is truncated (floor division). However in 3.x, the /
operator performs ‘true’ division, resulting in a float
instead of an integer (e.g. 1 / 2 = 0.5
). What this means is that your are now trying to use a float to reference a position in a list (e.g. my_list[0.5]
or even my_list[1.0]
), which will not work as Python is expecting an integer. Therefore you may first want to try using middle = (first + last) // 2
, adjusting so that the result returns what you expect. The //
indicates floor division in Python 3.x.
Related Posts:
- TypeError: list indices must be integers or slices, not list
- TypeError: slice indices must be integers or None or have an __index__ method
- Python cant convert ‘list’ object to str error [closed]
- Python – TypeError: ‘int’ object is not iterable
- Python – TypeError: ‘int’ object is not iterable
- How to overcome TypeError: unhashable type: ‘list’
- not all arguments converted during string formatting.. NO % variables
- What does the list() function do in Python?
- TypeError: not all arguments converted during string formatting python
- Relative imports in Python 3
- ModuleNotFoundError: No module named ‘requests’. But ‘requests’ already installed
- What are type hints in Python 3.5?
- ImportError: No module named ‘keras’
- TypeError: ‘list’ object cannot be interpreted as an integer
- ImportError: libcublas.so.9.0: cannot open shared object file
- How to install xlrd in python3 library
- How to import cv2 in python3?
- ‘python3’ is not recognized as an internal or external command, operable program or batch file
- How to find all the indexes of a recurring item in a list?
- Unable to initialize device PRN in Python
- Error when executing `jupyter notebook` (No such file or directory)
- How to resolve TypeError: ‘No Numeric Data to Plot’, when numeric data exists in Python
- python3 is not recognized as an internal or external command, operable program or batch file showing for creating django runserver
- python3 : The term ‘python3’ is not recognized as the name of a cmdlet
- How can I solve ” module ‘pandas’ has no attribute ‘scatter_matrix’ ” error?
- Getting a map() to return a list in Python 3.x
- Install numpy on python3.3 – Install pip for python3
- How to import cv2 in python3?
- Why did ‘reset_index(drop=True)’ function unwantedly remove column?
- TypeError: unsupported operand type(s) for -: ‘list’ and ‘list’
- Python: create a pandas data frame from a list
- Python 3 – ValueError: not enough values to unpack (expected 3, got 2)
- How to return dictionary keys as a list in Python?
- TypeError: ‘_io.TextIOWrapper’ object is not subscriptable
- python 3 – x for x for loops – how do they work?
- Visual Studio Python “Failed to launch the Python Process, please validate the path ‘python” & Error: spawn python ENOENT
- TypeError: module.__init__() takes at most 2 arguments (3 given)
- WinError 10061 – No Connection Could be made
- how do I upgrade pip on Mac?
- How can I reverse a list in Python?
- How to use filter, map, and reduce in Python 3
- converting time from UTC to CST
- What is the difference between Python’s list methods append and extend?
- Understanding slice notation
- PermissionError: [Errno 13] in Python
- FileNotFoundError: [WinError 2] The system cannot find the file specified:
- How to correct TypeError: Unicode-objects must be encoded before hashing?
- How to install python3 version of package via pip on Ubuntu?
- django: TypeError: ‘tuple’ object is not callable
- TypeError: method() takes 1 positional argument but 2 were given
- How can I get a list shape without using numpy?
- Understanding slice notation
- Add list to set?
- Infinite integer in Python
- I get a syntax error and an error saying illegal target for variable annotation. How do I fix it?
- How do I append lists in Prolog?
- Why do I get an UnsupportedOperationException when trying to remove an element from a List?
- Python: can’t assign to literal
- “Initializing” variables in python?
- Difference between except: and except Exception as e:
- Python TypeError must be str not int
- “Unicode Error “unicodeescape” codec can’t decode bytes… Cannot open text files in Python 3
- How to downgrade python from 3.7 to 3.6
- How to save a dictionary to a file?
- Merge two (or more) lists into one, in C# .NET
- Using Look Up Tables in Python
- Python3 Error: TypeError: Can’t convert ‘bytes’ object to str implicitly
- how to exit a python script in an if statement
- Incompatible types List of List and ArrayList of ArrayList
- Not able to pip install pickle in python 3.6
- convert csv file to list of dictionaries
- Decode Hex String in Python 3
- How to clear Tkinter Canvas?
- TypeError: ‘range’ object does not support item assignment
- How to install pip for Python 3 on Mac OS X?
- How to split elements of a list?
- Find object in list that has attribute equal to some value (that meets any condition)
- When to use a Map instead of a List in Java?
- ‘module’ has no attribute ‘urlencode’
- How to install PyQt4 on Windows using pip?
- How to install PyQt4 on Windows using pip?
- Add class to all list items of wp_nav_menu
- Nav menu of all posts in a custom post type
- Listing all sub-pages?
- Number of items in a menu
- Download all WordPress.com available themes, somewhere?
- Show Available Taxonomy List with Current Category
- Displaying list of cities according to the selected state. Using the WordPress hook
- Author list based on recently active
- Authors & profiles (and exclude ID’s)
- Display A list of Admins
- how to list all subdomain in wordpress multiuser
- confused about wp_list_pages() function – how to display selected top pages with all their subpages
- Posts as filtered list – expandable
- How can ι create my own (custom) WordPress table/list?
- adding a #hash to each link in list_pages()?
- I need advice for creating native WordPress directory site based on native WordPress functionality only
- Drodown list return issue
- How to create page that lists tags by initial letter?
- Way to show content of a post, but if exceeds character limit revert to excerpt?