I am currently attempting to work on converting a fairly sizeable JSON object
and convert it into a CSV format. However, when I attempt to do so, using a
conventional approach (that seems to work with other files). I am presented
with a ValueError: too many values to unpack
I have tried to
On Mon, Nov 12, 2012 at 11:41:59PM +, Joshua Landau wrote:
Dict comprehension:
{i:[] for i in [Test 1, Test 2, Test 3]}
In Python 2.6 this syntax is not supported. You can achieve the same
there via
dict((i, []) for i in ['Test 1', 'Test 2', 'Test 3'])
Also have a look at
',
'Test_2'
)
# Initialise the dictionary of lists
dict1 = {
'Test_1' : [],
'Test_2' : [],
}
instances = ('1')
# Loop through the list of tests
for Test in TestList:
print
print Test: , Test
# Append to the list for each instance
for instance in instances:
print
On 12 November 2012 22:26, NJ1706 nickj1...@googlemail.com wrote:
Chaps,
I am new to Python have inherited a test harness written in the language
that I am trying to extend.
The following code shows how dictionaries holding lists of commands are
handled in the script...
Start of Code_1
',
'Test_2'
]
Additionally, your comment here is somewhat pointless. The code says
*exactly* what your comment does, so why write it twice?
# List of tests
Don't need
# Initialise the dictionary of lists
Don't need
# Loop through the list of tests
Don't need
# Append to the list for each
I open a csv file and create a DictReader object. Subsequently, reading
lines from this file I try to update a dictionary of lists:
csvf=open(os.path.join(root,fcsv),'rb')
csvr=csv.DictReader(csvf)
refd=dict.fromkeys(csvr.fieldnames,[])
for row in csvr:
for (k,v) in row.items
Alex van der Spek zd...@xs4all.nl writes:
refd=dict.fromkeys(csvr.fieldnames,[]) ...
I do not understand why this appends v to every key k each time.
You have initialized every element of refd to the same list. Try
refd = dict((k,[]) for k in csvr.fieldnames)
instead.
--
On Tue, May 3, 2011 at 12:56 PM, Paul Rubin no.email@nospam.invalid wrote:
Alex van der Spek zd...@xs4all.nl writes:
refd=dict.fromkeys(csvr.fieldnames,[]) ...
I do not understand why this appends v to every key k each time.
You have initialized every element of refd to the same list.
Thank you! Would never have found that by myself.
Paul Rubin no.email@nospam.invalid wrote in message
news:7x7ha75zib@ruckus.brouhaha.com...
Alex van der Spek zd...@xs4all.nl writes:
refd=dict.fromkeys(csvr.fieldnames,[]) ...
I do not understand why this appends v to every key k each
Hi all,
hope you can help me understanding why the following happens:
In [213]: g = {'a': ['a1','a2'], 'b':['b1','b2']}
In [214]: rg = dict.fromkeys(g.keys(),[])
In [215]: rg
Out[215]: {'a': [], 'b': []}
In [216]: rg['a'].append('x')
In [217]: rg
Out[217]: {'a': ['x'], 'b': ['x']}
What I meant
On Tue, Nov 9, 2010 at 3:14 PM, Ciccio franap...@gmail.com wrote:
Hi all,
hope you can help me understanding why the following happens:
In [213]: g = {'a': ['a1','a2'], 'b':['b1','b2']}
In [214]: rg = dict.fromkeys(g.keys(),[])
The argument you pass which is used to fill the values of the
Ciccio wrote:
Hi all,
hope you can help me understanding why the following happens:
In [213]: g = {'a': ['a1','a2'], 'b':['b1','b2']}
In [214]: rg = dict.fromkeys(g.keys(),[])
In [215]: rg
Out[215]: {'a': [], 'b': []}
In [216]: rg['a'].append('x')
In [217]: rg
Out[217]: {'a': ['x'], 'b':
On 2:59 PM, Ciccio wrote:
Hi all,
hope you can help me understanding why the following happens:
In [213]: g = {'a': ['a1','a2'], 'b':['b1','b2']}
In [214]: rg = dict.fromkeys(g.keys(),[])
In [215]: rg
Out[215]: {'a': [], 'b': []}
In [216]: rg['a'].append('x')
In [217]: rg
Out[217]: {'a':
On 11/9/2010 9:14 AM, Ciccio wrote:
Hi all,
hope you can help me understanding why the following happens:
In [213]: g = {'a': ['a1','a2'], 'b':['b1','b2']}
In [214]: rg = dict.fromkeys(g.keys(),[])
If you rewrite this as
bl = []
rg = dict.fromkeys(g.keys(),bl)
is the answer any more
Il 09/11/2010 16:47, Terry Reedy ha scritto:
On 11/9/2010 9:14 AM, Ciccio wrote:
Hi all,
hope you can help me understanding why the following happens:
In [213]: g = {'a': ['a1','a2'], 'b':['b1','b2']}
In [214]: rg = dict.fromkeys(g.keys(),[])
If you rewrite this as
bl = []
rg =
Thank you all, this was timely and helpful.
francesco
--
http://mail.python.org/mailman/listinfo/python-list
On 11/9/2010 12:19 PM, Ciccio wrote:
Il 09/11/2010 16:47, Terry Reedy ha scritto:
On 11/9/2010 9:14 AM, Ciccio wrote:
Hi all,
hope you can help me understanding why the following happens:
In [213]: g = {'a': ['a1','a2'], 'b':['b1','b2']}
In [214]: rg = dict.fromkeys(g.keys(),[])
If you
On 11/9/2010 1:43 PM, Terry Reedy wrote:
... List *is* useful as an initializer for
collecitons.defaultdicts.
And it was useful when several members of this forum helped me to
develop a prime-number generator.
See http://www.mail-archive.com/python-list@python.org/msg288128.html.
(I meant
Okay that makes sense. I was assuming that list.append returned the
new list.
thanks
--
http://mail.python.org/mailman/listinfo/python-list
John Nagle schrieb:
Shaun wrote:
I'm trying to create a dictionary with lists as the value for each
key.
Try using a tuple, instead of a list, for each key. Tuples
are immutable, so there's no issue about a key changing while
being used in a dictionary.
Only if Shaun wanted to use
Hi,
Shaun wrote:
I'm trying to create a dictionary with lists as the value for each
key. I was looking for the most elegant way of doing it...
from collections import defaultdict
d = defaultdict(list)
d[joe].append(something)
d[joe].append(another)
d[jim].append(slow down, grasshopper
Shaun wrote:
testDict = {}
...
testDict [1] = testDict.get (1, []).append (Test0) # 1 does not
exist, create empty array
print testDict
testDict [1] = testDict.get (1, []).append (Test1)
print testDict
[ ... ]
However, the first printout gives {1: None} instead of the desired
{1:
Shaun wrote:
Hi,
I'm trying to create a dictionary with lists as the value for each
key. I was looking for the most elegant way of doing it...
Try using a tuple, instead of a list, for each key. Tuples
are immutable, so there's no issue about a key changing while
being used
On Sep 11, 9:42 am, Stefan Behnel stefan...@behnel.de wrote:
JBwrote:
I have created a small program that generates a project tree from a
dictionary. The dictionary is of key/value pairs where each key is a
directory, and each value is a list. The list have unique values
corresponding to
I have created a small program that generates a project tree from a
dictionary. The dictionary is of key/value pairs where each key is a
directory, and each value is a list. The list have unique values
corresponding to the key, which is a directory where each value in the
list becomes a
JB wrote:
I have created a small program that generates a project tree from a
dictionary. The dictionary is of key/value pairs where each key is a
directory, and each value is a list. The list have unique values
corresponding to the key, which is a directory where each value in the
list
I searched for an hour and don't see a solution to this (i assume
somewhat common) problem.
I have a very large dictionary of lists:
d = {a:[1,2], b:[2,3], c:[3]}
and i want to reverse the associativity of the integers thusly:
inverse(d) makes {1:[a], 2:[a,b], 3:[b,c]}
my solution expands
En Fri, 15 Jun 2007 00:20:33 -0300, [EMAIL PROTECTED] escribió:
I searched for an hour and don't see a solution to this (i assume
somewhat common) problem.
I have a very large dictionary of lists:
d = {a:[1,2], b:[2,3], c:[3]}
and i want to reverse the associativity of the integers thusly
On Jun 14, 8:20 pm, [EMAIL PROTECTED] wrote:
I have a very large dictionary of lists:
d = {a:[1,2], b:[2,3], c:[3]}
and i want to reverse the associativity of the integers thusly:
inverse(d) makes {1:[a], 2:[a,b], 3:[b,c]}
Try using setdefault:
d = {'a':[1,2], 'b':[2,3], 'c':[3]}
r
wswilson a écrit :
Here is my code:
listing = {'id': ['a', 'b', 'c'], 'name': ['Joe', 'Jane', 'Bob']}
I need to output:
id name
a Joe
b Jane
c Bob
I could do:
print 'id', 'name'
for id, name in zip(listing['id'], listing['name']): print id, name
but that only works if there
Here is my code:
listing = {'id': ['a', 'b', 'c'], 'name': ['Joe', 'Jane', 'Bob']}
I need to output:
id name
a Joe
b Jane
c Bob
I could do:
print 'id', 'name'
for id, name in zip(listing['id'], listing['name']): print id, name
but that only works if there are two entries in the dictionary,
On Apr 18, 7:39 pm, wswilson [EMAIL PROTECTED] wrote:
Here is my code:
listing = {'id': ['a', 'b', 'c'], 'name': ['Joe', 'Jane', 'Bob']}
I need to output:
id name
a Joe
b Jane
c Bob
I could do:
print 'id', 'name'
for id, name in zip(listing['id'], listing['name']): print id, name
wswilson wrote:
Here is my code:
listing = {'id': ['a', 'b', 'c'], 'name': ['Joe', 'Jane', 'Bob']}
I need to output:
id name
a Joe
b Jane
c Bob
I could do:
print 'id', 'name'
for id, name in zip(listing['id'], listing['name']): print id, name
but that only works if there are
On Apr 18, 2:54 pm, Arnaud Delobelle [EMAIL PROTECTED] wrote:
On Apr 18, 7:39 pm, wswilson [EMAIL PROTECTED] wrote:
Here is my code:
listing = {'id': ['a', 'b', 'c'], 'name': ['Joe', 'Jane', 'Bob']}
I need to output:
id name
a Joe
b Jane
c Bob
I could do:
print 'id',
-Original Message-
From: [EMAIL PROTECTED]
[mailto:python-
[EMAIL PROTECTED] On Behalf Of wswilson
Sent: Wednesday, April 18, 2007 1:39 PM
To: python-list@python.org
Subject: Iterate through a dictionary of lists one line at a time
Here is my code:
listing = {'id': ['a', 'b
interpreter, I attempt to insert
a dictionary of lists into the module represented by the pointer
'pmod' passed to the DLL from the
main application.
The dictionary of lists is created with the following call:
PyObject * abm_dict = Py_BuildValue( {s:O,s:O,s:O,s:O,s:O,s:O,s:O,s:O,s:O
36 matches
Mail list logo