Re: [Tutor] Sorting large numbers of co-ordinate pairs

2009-03-12 Thread Lie Ryan
Dinesh B Vadhia wrote: Have a large number (> 1bn) of integer co-ordinates (i, j). The i are ordered and the j unordered. I want to create (j, i) with j ordered and i unordered ie. from: ... 6940, 22886 6940, 38277 6940, 43788 ... to: ... 38277, 567 38277, 90023 38277, 6940 ... I've

Re: [Tutor] merging dictionary values based on key

2009-03-12 Thread Martin Walsh
> greg whittier wrote: >> On Thu, Mar 12, 2009 at 4:24 PM, ski wrote: >> mylist = [{'a': 'x123', 'b':'12'}, {'a': 'x234', 'b': 'd33', 'c': >> 'a23'}, {'a': 'x234', 'c': 'XX123'} ] >>> where mylist has nth number of dictionaries and i want to merge the >>> values >>> of the keys that a

Re: [Tutor] Issues Parsing XML

2009-03-12 Thread Moos Heintzen
I'm a little bored, so I wrote a function that gets elements and puts them in a dictionary. Missing elements are just an empty string. http://gist.github.com/78385 Usage: >>> d = process_finding(findings[0]) >>> ", ".join(map(lambda e: d[e], elements)) u'V0006310, NF, , , GD, 2.0.8.8, TRUE, DTBI

Re: [Tutor] Issues Parsing XML

2009-03-12 Thread Moos Heintzen
So you want one line for each element? Easy: # Get elements findings = domDatasource.getElementsByTagName('FINDING') # Get the text of all direct child nodes in each element # That's assuming every child has a TEXT_NODE node. lines = [] for finding in findings: lines.append([f.firstChild.d

Re: [Tutor] merging dictionary values based on key

2009-03-12 Thread ski
how would you do this for a specific key instead of all the keys? greg whittier wrote: On Thu, Mar 12, 2009 at 4:24 PM, ski wrote: Hello, I have this issue, which I am unsure on how to solve. mylist1 = {'a': 'x123', 'b':'12'} mylist2 = {'a': 'x234', 'c': 'a23'} for k in mylist2: ... if

Re: [Tutor] Issues Parsing XML

2009-03-12 Thread Dave Kuhlman
On Thu, Mar 12, 2009 at 08:47:24PM +0100, Stefan Behnel wrote: > m...@marcd.org wrote: [snip] > > There is another "DOM Model" in the stdlib. It's called ElementTree and is > generally a lot easier to use. For example, to find the text content of an > element called "element_that_has_text_content

Re: [Tutor] merging dictionary values based on key

2009-03-12 Thread greg whittier
On Thu, Mar 12, 2009 at 4:24 PM, ski wrote: > Hello, > I have this issue, which I am unsure on how to solve. > mylist1 = {'a': 'x123', 'b':'12'} mylist2 = {'a': 'x234', 'c': 'a23'} for k in mylist2: > ...     if k in mylist1: > ...             mylist1[k] = [mylist1[k], mylist2[k]] >

[Tutor] merging dictionary values based on key

2009-03-12 Thread ski
Hello, I have this issue, which I am unsure on how to solve. >>> mylist1 = {'a': 'x123', 'b':'12'} >>> mylist2 = {'a': 'x234', 'c': 'a23'} >>> for k in mylist2: ... if k in mylist1: ... mylist1[k] = [mylist1[k], mylist2[k]] ... else: ... mylist1[k] = mylist2[k] ...

Re: [Tutor] Issues Parsing XML

2009-03-12 Thread Stefan Behnel
m...@marcd.org wrote: > I am new to Python and as a first project decided to try to parse an XML > report using Python. I have the following, which works to extract one > element. I am stuck, however, at one element. I want to extract several > differenct elements per line, creating a comma sepa

Re: [Tutor] reading lists from a text file

2009-03-12 Thread Kent Johnson
2009/3/12 Emad Nawfal (عماد نوفل) : > Hi Tutors, > I've never had a situation in which this was useful for me, but I'm just > curious. > If there is a text file that has a list or number of lists in it, is there > is a way to read the lists in the file as lists, and not as a string. Sample > file a

Re: [Tutor] Sorting large numbers of co-ordinate pairs

2009-03-12 Thread Alan Gauld
"Dinesh B Vadhia" wrote Have a large number (> 1bn) of integer co-ordinates (i, j). I want to create (j, i) with j ordered and i unordered ie. I've tried the dictionary route and it works perfectly for small set of co-ordinate pairs but not for large sets as it hits memory capacity. One

Re: [Tutor] reading lists from a text file

2009-03-12 Thread Noufal Ibrahim
Emad Nawfal (عماد نوفل) wrote: Hi Tutors, I've never had a situation in which this was useful for me, but I'm just curious. If there is a text file that has a list or number of lists in it, is there is a way to read the lists in the file as lists, and not as a string. Sample file attached.

Re: [Tutor] reading lists from a text file

2009-03-12 Thread Alan Gauld
"Emad Nawfal (عماد نوفل)" wrote If there is a text file that has a list or number of lists in it, is there is a way to read the lists in the file as lists, and not as a string. Sample file attached. Not that I know of. If you made the file include assignments to variables or one big list

Re: [Tutor] loop performance in global namespace (python-2.6.1)

2009-03-12 Thread Kent Johnson
On Thu, Mar 12, 2009 at 11:41 AM, spir wrote: > Le Thu, 12 Mar 2009 11:13:33 -0400, > Kent Johnson s'exprima ainsi: > >> Because local name lookup is faster than global name lookup. Local >> variables are stored in an array in the stack frame and accessed by >> index. Global names are stored in a

[Tutor] reading lists from a text file

2009-03-12 Thread عماد نوفل
Hi Tutors, I've never had a situation in which this was useful for me, but I'm just curious. If there is a text file that has a list or number of lists in it, is there is a way to read the lists in the file as lists, and not as a string. Sample file attached. -- لا أعرف مظلوما تواطأ الناس علي هض

Re: [Tutor] loop performance in global namespace (python-2.6.1)

2009-03-12 Thread spir
Le Thu, 12 Mar 2009 11:13:33 -0400, Kent Johnson s'exprima ainsi: > Because local name lookup is faster than global name lookup. Local > variables are stored in an array in the stack frame and accessed by > index. Global names are stored in a dict and accessed with dict access > (dict.__getitem__

Re: [Tutor] loop performance in global namespace (python-2.6.1)

2009-03-12 Thread Kent Johnson
On Thu, Mar 12, 2009 at 8:13 AM, Poor Yorick wrote: > In the following snippet, the loop in the global namespace takes twice as > long > as the loop in the function namespace.  Why? Because local name lookup is faster than global name lookup. Local variables are stored in an array in the stack fr

Re: [Tutor] Sorting large numbers of co-ordinate pairs

2009-03-12 Thread Kent Johnson
On Thu, Mar 12, 2009 at 9:43 AM, Dinesh B Vadhia wrote: > Have a large number (> 1bn) of integer co-ordinates (i, j).  The i are > ordered and the j unordered. > > I want to create (j, i) with j ordered and i unordered ie. > > from: > > ... > 6940, 22886 > 6940, 38277 > 6940, 43788 > ... > > to: >

[Tutor] Sorting large numbers of co-ordinate pairs

2009-03-12 Thread Dinesh B Vadhia
Have a large number (> 1bn) of integer co-ordinates (i, j). The i are ordered and the j unordered. I want to create (j, i) with j ordered and i unordered ie. from: ... 6940, 22886 6940, 38277 6940, 43788 ... to: ... 38277, 567 38277, 90023 38277, 6940 ... I've tried the dictionary route and

[Tutor] loop performance in global namespace (python-2.6.1)

2009-03-12 Thread Poor Yorick
In the following snippet, the loop in the global namespace takes twice as long as the loop in the function namespace. Why? limit = 5000 def f1(): counter = 0 while counter < limit: counter += 1 time1 = time.time() f1() print(time.time() - time