save dictionary to a file without brackets.

Giuseppe Amatulli giuseppe.amatulli at gmail.com
Thu Aug 9 16:35:54 EDT 2012


thanks for the fast replies
my testing were very closed to yours but i did not know how

On 9 August 2012 15:25, Oscar Benjamin <oscar.j.benjamin at gmail.com> wrote:
>
> On Aug 9, 2012 9:17 PM, <giuseppe.amatulli at gmail.com> wrote:
>>
>> Hi,
>> I have a dict() unique
>> like this
>> {(4, 5): 1, (5, 4): 1, (4, 4): 2, (2, 3): 1, (4, 3): 2}
>> and i want to print to a file without the brackets comas and semicolon in
>> order to obtain something like this?
>> 4 5 1
>> 5 4 1
>> 4 4 2
>> 2 3 1
>> 4 3 2
>> Any ideas?
>> Thanks in advance
>
> How's this?
>
> from __future__ import print_function
>
> output = open("out.txt", "w")
>
> for (a, b), c in d.items():
>     print(a, b, c, file=output)
>
> output.close()
>
> Oscar.
>> --
>> http://mail.python.org/mailman/listinfo/python-list



-- 
Giuseppe Amatulli
Web: www.spatial-ecology.net



More information about the Python-list mailing list