I believe the syntax you were looking for is as follows:
import csv with open('coors.csv', mode='r') as infile: reader = csv.reader(infile) with open('coors_new.csv', mode='w') as outfile: writer = csv.writer(outfile) mydict = {rows[0]:rows[1] for rows in reader}
Alternately, for python <= 2.7.1, you want:
mydict = dict((rows[0],rows[1]) for rows in reader)
Related Posts:
- Writing a dictionary to a csv file with one line for every ‘key: value’
- convert csv file to list of dictionaries
- Iterating over dictionaries using ‘for’ loops
- TypeError: list indices must be integers or slices, not str
- How do I sort a dictionary by value?
- How do I sort a dictionary by value?
- Check if a given key already exists in a dictionary
- Writing a pandas DataFrame to CSV file
- How does collections.defaultdict work?
- Python Dictionary Comprehension
- Is a Python dictionary an example of a hash table?
- Converting dictionary to JSON
- How do I merge two dictionaries in a single expression (taking union of dictionaries)?
- Python list of dictionaries search
- Updating a dictionary in python
- How to avoid “RuntimeError: dictionary changed size during iteration” error?
- unhashable type: ‘dict’ Type Error [duplicate]
- ValueError : I/O operation on closed file
- if else in a list comprehension
- TypeError: ‘dict’ object is not callable
- csv.Error: iterator should return strings, not bytes
- Error: ” ‘dict’ object has no attribute ‘iteritems’ “
- Getting key with maximum value in dictionary?
- Error: ” ‘dict’ object has no attribute ‘iteritems’ “
- How can I get dictionary key as variable directly in Python (not by searching from value)?
- How can I remove a key from a Python dictionary?
- append multiple values for one key in a dictionary [duplicate]
- Convert a python dict to a string and back
- List comprehension on a nested list?
- Delete an element from a dictionary
- Python Error io.UnsupportedOperation: not readable
- How to add multiple values per key in python dictionary
- How to get the union of two lists using list comprehension?
- load csv into 2D matrix with numpy for plotting
- Dump a NumPy array into a csv file
- (unicode error) ‘unicodeescape’ codec can’t decode bytes in position 2-3: truncated \UXXXXXXXX escape
- Determine the type of an object?
- enumerate() for dictionary in python
- Reverse / invert a dictionary mapping
- Creating 2D dictionary in Python
- How to load a tsv file into a Pandas DataFrame?
- How to print a dictionary’s key?
- Converting Dictionary to List?
- How to pretty print nested dictionaries?
- Difference between writerow() and writerows() methods of Python csv module
- Create a .csv file with values from a Python list
- Convert XML to CSV file
- TypeError: list indices must be integers or slices, not str
- How to index into a dictionary?
- Add a new item to a dictionary in Python
- How can I add new keys to a dictionary?
- How can I get list of values from dict?
- Convert from CSV to array in Python
- TypeError: string indices must be integers, not str // working with dict
- How do I format a string using a dictionary in python-3.x?
- Map to List error: Series object not callable
- How to return dictionary keys as a list in Python?
- How can I create an array/list of dictionaries in python?
- Comparing two dictionaries and checking how many (key, value) pairs are equal
- How to save a dictionary to a file?
- ValueError: x and y must be the same size
- Mapping over values in a python dictionary
- TypeError: ‘dict_keys’ object does not support indexing
- OSError: Initializing from file failed on csv in Pandas
- How to convert an XML string to a dictionary?
- Why is there no tuple comprehension in Python?
- Why is there no tuple comprehension in Python?
- How do I print the key-value pairs of a dictionary in python
- How do I print the key-value pairs of a dictionary in python
- How do I make a dictionary with multiple keys to one value?
- Python: How to check if keys exists and retrieve value from Dictionary in descending priority
- Appending values to dictionary in Python
- Python dictionary from an object’s fields
- How to convert a file into a dictionary?
- Python CSV error: line contains NULL byte
- Python Add to dictionary loop
- AttributeError: ‘str’ object has no attribute ‘items’
- Python CSV Error: sequence expected
- AttributeError: ‘float’ object has no attribute ‘split’4
- How to add pandas data to an existing csv file?
- JSON object must be str, bytes or bytearray, not dict
- Declaring a multi dimensional dictionary in python
- how to concatenate two dictionaries to create a new one in Python?
- _csv.Error: field larger than field limit (131072)
- python-How to solve KeyError: 2?
- How to search through dictionaries?
- Is it possible to use ‘else’ in a list comprehension?
- Change the name of a key in dictionary
- What is an easy way to implement fprintf in python?
- How can I extract all values from a dictionary in Python?
- Writing Python lists to columns in csv
- Create a list with initial capacity in Python
- Iterating over dictionary items(), values(), keys() in Python 3
- Flatten nested dictionaries, compressing keys
- Error in Reading a csv file in pandas[CParserError: Error tokenizing data. C error: Buffer overflow caught – possible malformed input file.]
- python dictionary error AttributeError: ‘list’ object has no attribute ‘keys’
- Convert list of dictionaries to a pandas DataFrame
- How to read a CSV file from a URL with Python?
- How to print both strings in a dictionary in Python
- How to import a csv-file into a data array?