Clearly you’re passing in d.keys()
to your shuffle
function. Probably this was written with python2.x (when d.keys()
returned a list). With python3.x, d.keys()
returns a dict_keys
object which behaves a lot more like a set
than a list
. As such, it can’t be indexed.
The solution is to pass list(d.keys())
(or simply list(d)
) to shuffle
.
Related Posts:
- Updating a dictionary in python
- How to copy a dictionary and only edit the copy
- TypeError: ‘type’ object is not subscriptable when indexing in to a dictionary
- Error: ” ‘dict’ object has no attribute ‘iteritems’ “
- Error: ” ‘dict’ object has no attribute ‘iteritems’ “
- Are dictionaries ordered in Python 3.6+?
- enumerate() for dictionary in python
- How do I format a string using a dictionary in python-3.x?
- How to return dictionary keys as a list in Python?
- How to save a dictionary to a file?
- What is an easy way to implement fprintf in python?
- Accessing dict_keys element by index in Python3
- Iterating over dictionary items(), values(), keys() in Python 3
- SyntaxError: unexpected EOF while parsing
- TypeError: only integer scalar arrays can be converted to a scalar index with 1D numpy indices array
- Microsoft Visual C++ 14.0 is required (Unable to find vcvarsall.bat)
- How to install pip with Python 3?
- Import Error: No module named numpy
- TypeError: a bytes-like object is required, not ‘str’ when writing to a file in Python3
- How does collections.defaultdict work?
- Relative imports in Python 3
- Best way to convert string to bytes in Python 3?
- TypeError: not all arguments converted during string formatting python
- Using Python 3 in virtualenv
- WinError 2 The system cannot find the file specified (Python)
- hashlib.md5() TypeError: Unicode-objects must be encoded before hashing
- Python list of dictionaries search
- How to avoid “RuntimeError: dictionary changed size during iteration” error?
- Could not find a version that satisfies the requirement tensorflow
- Local variable referenced before assignment?
- AttributeError: ‘module’ object has no attribute ‘urlopen’
- Can’t fix “zipimport.ZipImportError: can’t decompress data; zlib not available” when I type in “python3.6 get-pip.py”
- ‘method’ object is not subscriptable. Don’t know what’s wrong
- error UnicodeDecodeError: ‘utf-8’ codec can’t decode byte 0xff in position 0: invalid start byte
- How to upgrade pip3?
- Getting key with maximum value in dictionary?
- TypeError: Missing 1 required positional argument: ‘self’
- What is __pycache__?
- SystemError: Parent module ” not loaded, cannot perform relative import
- TypeError: ‘<=' not supported between instances of 'str' and 'int' [duplicate]
- TypeError: unsupported operand type(s) for -: ‘str’ and ‘int’
- How to upgrade pip3?
- How to Read .txt in Pandas
- TypeError: can’t use a string pattern on a bytes-like object in re.findall()
- TypeError: cannot convert the series to
- Pinging servers in Python
- Add Legend to Seaborn point plot
- How to pass arguments to a Button command in Tkinter?
- How to remove specific substrings from a set of strings in Python?
- Type error: cannot convert the series to
- How to remove punctuation marks from a string in Python 3.x using .translate()?
- Subplot for seaborn boxplot
- Determine the type of an object?
- Why Python 3.6.1 throws AttributeError: module ‘enum’ has no attribute ‘IntFlag’?
- Creating 2D dictionary in Python
- Converting Dictionary to List?
- How to pretty print nested dictionaries?
- How to use sys.exit() in Python
- How to index into a dictionary?
- installing urllib in Python3.6
- Add a new item to a dictionary in Python
- What is sys.maxint in Python 3?
- How can I add new keys to a dictionary?
- How can I install Python’s pip3 on my Mac?
- TypeError: string indices must be integers, not str // working with dict
- What is the meaning of ‘for _ in range()
- Python: AttributeError: ‘_io.TextIOWrapper’ object has no attribute ‘split’
- Pip – Fatal error in launcher: Unable to create process using ‘”‘
- How to convert ‘binary string’ to normal string in Python3?
- ImportError: No module named ‘yaml’
- TypeError: ‘_io.TextIOWrapper’ object is not subscriptable
- Properly formatted multiplication table
- How do I print the key-value pairs of a dictionary in python
- python3 TypeError: ‘function’ object is not iterable
- How to print multiple lines of text with Python
- Python dictionary from an object’s fields
- How to compare individual characters in two strings in Python 3
- How do I run pip on python for windows?
- Need to install urllib2 for Python 3.5.1
- ImportError: No module named ‘xlrd’
- Moving Average Pandas
- TypeError: ‘set’ object does not support indexing
- What does {0} mean in this Python string?
- Tab Error in Python
- Root mean square of a function in python
- Python 3.5.1 urllib has no attribute request
- how to concatenate two dictionaries to create a new one in Python?
- matplotlib: plot multiple columns of pandas data frame on the bar chart
- Why do I get this error “TypeError: ‘method’ object is not iterable”?
- What is the purpose of dollar sign in this Python3 string formatting expression?
- What is the meaning of “int(a[::-1])” in Python?
- How can I extract all values from a dictionary in Python?
- Getting a name error when trying to input a string [duplicate]
- How to install NumPy for Python 3.6
- Error loading MySQLdb module: No module named ‘MySQLdb’
- How do you switch between python 2 and 3, and vice versa?
- Python webbrowser.open() to open Chrome browser
- Undefined variable error in function
- Python 3 integer division [duplicate]
- Python – difference between two strings