Re: Compare list entry from csv files

2012-11-30 Thread Anatoli Hristov
> As I said before, process both files into lists, one that you treat as > constant (and therefore capitalized) and the other containing the data > you intend to modify. > > It'd be much cleaner if you did all that input file parsing stuff in one > function, returning only the lists. Call it just

Re: Compare list entry from csv files

2012-11-30 Thread Anatoli Hristov
> Can you print ex_phone first. You are opening the files in text mode > so I wonder if the line endings are causing you to read and extra > "line" in between. Can you try reading the csv as "rb" instead of > "rt"? Yes I did this: use the global list PHONELIST and opening the CSV in binary - it wo

Re: Compare list entry from csv files

2012-11-29 Thread Dave Angel
On 11/29/2012 05:22 AM, Anatoli Hristov wrote: > > Hello, > > Tried to document a little bit the script, but I'm not that good in that too > :) > > The only problem I have is that I cant compare other field than the > first one in > for ex_phone in phones: > telstr = ex_phone[0].lower() >

RE: Compare list entry from csv files

2012-11-29 Thread Prasad, Ramit
Anatoli Hristov wrote: > Hello, > > Tried to document a little bit the script, but I'm not that good in that too > :) > > The only problem I have is that I cant compare other field than the > first one in > for ex_phone in phones: > telstr = ex_phone[0].lower() > When I use telstr = ex_p

Re: Compare list entry from csv files

2012-11-29 Thread Thomas Bach
Can you please cut the message you are responding to the relevant parts? On Thu, Nov 29, 2012 at 11:22:28AM +0100, Anatoli Hristov wrote: > The only problem I have is that I cant compare other field than the > first one in > for ex_phone in phones: > telstr = ex_phone[0].lower() > When I u

Re: Compare list entry from csv files

2012-11-29 Thread Anatoli Hristov
On Tue, Nov 27, 2012 at 9:41 PM, Neil Cerutti wrote: > On 2012-11-27, Anatoli Hristov wrote: >> Thank you all for the help, but I figured that out and the >> program now works perfect. I would appreciate if you have some >> notes about my script as I'm noob :) Here is the code: >> >> import csv >

Re: Compare list entry from csv files

2012-11-27 Thread Neil Cerutti
On 2012-11-27, Anatoli Hristov wrote: > Thank you all for the help, but I figured that out and the > program now works perfect. I would appreciate if you have some > notes about my script as I'm noob :) Here is the code: > > import csv > > origf = open('c:/Working/Test_phonebook.csv', 'rt') > secf

Re: Compare list entry from csv files

2012-11-27 Thread Dave Angel
On 11/27/2012 01:57 PM, Anatoli Hristov wrote: > > > Thank you all for the help, but I figured that out and the program now > works perfect. Wow! > I would appreciate if you have some notes about my > script as I'm noob :) > Here is the code: > > import csv > > origf = open('c:/Working/Test_pho

Re: Compare list entry from csv files

2012-11-27 Thread Anatoli Hristov
On Tue, Nov 27, 2012 at 4:05 PM, Neil Cerutti wrote: > On 2012-11-27, Anatoli Hristov wrote: >> Thanks for your help. I will do my best for the forum :) >> >> I advanced a little bit with the algorithm and at least I can >> now extract and compare the fields :) For my beginner skills I >> think t

Re: Compare list entry from csv files

2012-11-27 Thread Neil Cerutti
On 2012-11-27, Anatoli Hristov wrote: > Thanks for your help. I will do my best for the forum :) > > I advanced a little bit with the algorithm and at least I can > now extract and compare the fields :) For my beginner skills I > think this is too much for me. Now next step is to add the > second

Re: Compare list entry from csv files

2012-11-27 Thread Anatoli Hristov
On Tue, Nov 27, 2012 at 4:23 AM, Dave Angel wrote: > On 11/26/2012 05:27 PM, Anatoli Hristov wrote: >> I understand, but in my case I have for sure the field "Name" in the >> second file that contains at least the first or the last name on it... >> So probably it should be possible:) >> The Name "

Re: Compare list entry from csv files

2012-11-26 Thread Dave Angel
On 11/26/2012 05:27 PM, Anatoli Hristov wrote: > I understand, but in my case I have for sure the field "Name" in the > second file that contains at least the first or the last name on it... > So probably it should be possible:) > The Name "Billgatesmicrosoft" contains the word "Gates" so logically

Re: Compare list entry from csv files

2012-11-26 Thread Emile van Sebille
Anatoli Hristov wrote: I understand, but in my case I have for sure the field "Name" in the second file that contains at least the first or the last name on it... So probably it should be possible:) The Name "Billgatesmicrosoft" contains the word "Gates" so logically I might find a solution for i

Re: Compare list entry from csv files

2012-11-26 Thread Anatoli Hristov
I understand, but in my case I have for sure the field "Name" in the second file that contains at least the first or the last name on it... So probably it should be possible:) The Name "Billgatesmicrosoft" contains the word "Gates" so logically I might find a solution for it. Thanks On Mon, Nov 2

Re: Compare list entry from csv files

2012-11-26 Thread Dave Angel
On 11/26/2012 04:08 PM, Anatoli Hristov wrote: > Hello, > > I'm trying to complete a namebook CSV file with missing phone numbers > which are in another CSV file. > the namebook file is structured: > First name;Lastname; Address; City; Country; Phone number, where the > phone number is missing. > >

Re: compare list

2005-11-15 Thread Bengt Richter
On 15 Nov 2005 04:51:05 -0800, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > >Simon Brunning wrote: >> On 15/11/05, Ben Bush <[EMAIL PROTECTED]> wrote: >> > I found I named the following python file as sets.py, which brought the >> > problem (is that right?). i changed it to other name and it w

Re: compare list

2005-11-15 Thread [EMAIL PROTECTED]
Simon Brunning wrote: > On 15/11/05, Ben Bush <[EMAIL PROTECTED]> wrote: > > I found I named the following python file as sets.py, which brought the > > problem (is that right?). i changed it to other name and it works. > > But the logic output is wrong. > > from sets import Set as set > > lisA=[1

Re: compare list

2005-11-15 Thread Simon Brunning
On 15/11/05, Ben Bush <[EMAIL PROTECTED]> wrote: > I found I named the following python file as sets.py, which brought the > problem (is that right?). i changed it to other name and it works. > But the logic output is wrong. > from sets import Set as set > lisA=[1,2,5,9] > lisB=[9,5,0,2] > lisC=[9,

Re: compare list

2005-11-15 Thread Richie Hindle
Ben, > But the logic output is wrong. > from sets import Set as set > lisA=[1,2,5,9] > lisB=[9,5,0,2] > lisC=[9,5,0,1] > def two(sequence1, sequence2): > set1, set2 = set(sequence1), set(sequence2) > return len(set1.intersection(set2)) == 2 > print two(lisA,lisB) > False(should be true!)

Re: compare list

2005-11-15 Thread Ben Bush
On 11/15/05, Simon Brunning <[EMAIL PROTECTED]> wrote: On 15/11/05, Ben Bush <[EMAIL PROTECTED]> wrote:> an error reported: > Traceback (most recent call last):>   File> "C:\Python23\lib\site-packages\Pythonwin\pywin\framework\scriptutils.py",> line 310, in RunScript> exec codeObject in __main

Re: compare list

2005-11-15 Thread Simon Brunning
On 15/11/05, Ben Bush <[EMAIL PROTECTED]> wrote: > an error reported: > Traceback (most recent call last): > File > "C:\Python23\lib\site-packages\Pythonwin\pywin\framework\scriptutils.py", > line 310, in RunScript > exec codeObject in __main__.__dict__ > File "C:\temp\try.py", line 8, in ?

Re: compare list

2005-11-15 Thread Ben Bush
On 11/15/05, Simon Brunning <[EMAIL PROTECTED]> wrote: On 15/11/05, Shi Mu <[EMAIL PROTECTED]> wrote: > Yes, i am using python 2.3,> I have used from sets import *> but still report the same error:> > > Traceback (most recent call last):> > >   File "", line 1, in ? > > > NameError: name 'set' is

Re: compare list

2005-11-15 Thread Richie Hindle
[Shi] > Yes, i am using python 2.3, > I have used from sets import * > but still report the same error: > > > Traceback (most recent call last): > > > File "", line 1, in ? > > > NameError: name 'set' is not defined It's 'Set', not 'set'. Try this: >>> import sets >>> dir(sets) -- Richie Hi

Re: compare list

2005-11-15 Thread Simon Brunning
On 15/11/05, Shi Mu <[EMAIL PROTECTED]> wrote: > Yes, i am using python 2.3, > I have used from sets import * > but still report the same error: > > > Traceback (most recent call last): > > > File "", line 1, in ? > > > NameError: name 'set' is not defined I said analogous, not identical. try (u

Re: compare list

2005-11-15 Thread Shi Mu
On 11/15/05, Simon Brunning <[EMAIL PROTECTED]> wrote: > On 15/11/05, Shi Mu <[EMAIL PROTECTED]> wrote: > > it does not work. > > >>> len(set(lisA).intersection(set(lisB))) == 2 > > Traceback (most recent call last): > > File "", line 1, in ? > > NameError: name 'set' is not defined > > 'set' is

Re: compare list

2005-11-15 Thread Simon Brunning
On 15/11/05, Shi Mu <[EMAIL PROTECTED]> wrote: > it does not work. > >>> len(set(lisA).intersection(set(lisB))) == 2 > Traceback (most recent call last): > File "", line 1, in ? > NameError: name 'set' is not defined 'set' is introduced as a built-in at Python 2.4. If you have 2.3, there's an an

Re: compare list

2005-11-15 Thread Shi Mu
On 11/15/05, Brian van den Broek <[EMAIL PROTECTED]> wrote: > Shi Mu said unto the world upon 2005-11-15 01:30: > >>Hey Ben, > >> > >>first, as expected, the other two answers you received are better. :-) > >> > >>Sets are much better optimized for things like membership testing than > >>are lists.

Re: compare list

2005-11-15 Thread Ben Bush
On 11/15/05, Brian van den Broek <[EMAIL PROTECTED]> wrote: Ben Bush said unto the world upon 2005-11-15 01:24: >>  Unfortunately, the indents got screwed up along the way. But the part>>>of my code you asked about was:for item in list1:>>if item in list2:>>if item + 1 in list1 and

Re: compare list

2005-11-15 Thread Brian van den Broek
Ben Bush said unto the world upon 2005-11-15 01:24: > > Unfortunately, the indents got screwed up along the way. But the part > >>of my code you asked about was: >> >>for item in list1: >>if item in list2: >>if item + 1 in list1 and item + 1 in list2: >>return True >>

Re: compare list

2005-11-15 Thread Brian van den Broek
Shi Mu said unto the world upon 2005-11-15 01:30: >>Hey Ben, >> >>first, as expected, the other two answers you received are better. :-) >> >>Sets are much better optimized for things like membership testing than >>are lists. I'm not competent to explain why; indeed, I keep >>overlooking them mysel

Re: compare list

2005-11-14 Thread Ben Bush
On 11/14/05, Ben Bush <[EMAIL PROTECTED]> wrote: Hijacking Brian's response since my newsserver never god Ben's originalrequest...:I would program this at a reasonably high abstraction level, based on sets -- since you say order doesn't matter, sets are more appropriatethan lists anyway.  For e

Re: compare list

2005-11-14 Thread Shi Mu
> Hey Ben, > > first, as expected, the other two answers you received are better. :-) > > Sets are much better optimized for things like membership testing than > are lists. I'm not competent to explain why; indeed, I keep > overlooking them myself :-( > > Unfortunately, the indents got screwed up

Re: compare list

2005-11-14 Thread Ben Bush
  Hi Brian, regarding "if item + 1 in list1 and item + 1 in list2:", my understanding is this will check whether the following item in each list is the same. How does the code permit the situation that the order does not matter? For example, for lisA and lisB, the comparison is true and the two lis

Re: compare list

2005-11-14 Thread Brian van den Broek
Ben Bush said unto the world upon 2005-11-14 23:20: > > On 11/14/05, Brian van den Broek <[EMAIL PROTECTED]> wrote: > >>Ben Bush said unto the world upon 2005-11-14 05:51: >> >>>I have four lists: >>>lisA=[1,2,3,4,5,6,9] >>>lisB=[1,6,5] >>>lisC=[5,6,3] >>>lisD=[11,14,12,15] >>>how can I write

Re: compare list

2005-11-14 Thread Ben Bush
[snip]That's potentially very expensive for large lists, although simplyconverting the lists to sets should give a significant speed up.  I think the following is *possibly* as good a way as any.>>> def compare(list1, list2):   intersection = sorted(list(set(list1) & set(list2)))   for i i

Re: compare list

2005-11-14 Thread Ben Bush
Hijacking Brian's response since my newsserver never god Ben's originalrequest...:I would program this at a reasonably high abstraction level, based on sets -- since you say order doesn't matter, sets are more appropriatethan lists anyway.  For example:def two_cont_in_common(x, y):   common = set(

Re: compare list

2005-11-14 Thread Ben Bush
what does the following code mean?  if item in list2:                        if item + 1 in list1 and item + 1 in list2:  On 11/14/05, Brian van den Broek <[EMAIL PROTECTED]> wrote: Ben Bush said unto the world upon 2005-11-14 05:51:> I have four lists:> lisA=[1,2,3,4,5,6,9] > lisB=[1,6,5]> lisC=[5

Re: compare list

2005-11-14 Thread Duncan Smith
Brian van den Broek wrote: > Ben Bush said unto the world upon 2005-11-14 05:51: > >> I have four lists: >> lisA=[1,2,3,4,5,6,9] >> lisB=[1,6,5] >> lisC=[5,6,3] >> lisD=[11,14,12,15] >> how can I write a function to compare lisB, lisC and lisD with lisA, >> if they >> share two continuous elements

Re: compare list

2005-11-14 Thread Alex Martelli
Brian van den Broek <[EMAIL PROTECTED]> wrote: > Ben Bush said unto the world upon 2005-11-14 05:51: > > I have four lists: > > lisA=[1,2,3,4,5,6,9] > > lisB=[1,6,5] > > lisC=[5,6,3] > > lisD=[11,14,12,15] > > how can I write a function to compare lisB, lisC and lisD with lisA, if they > > share t

Re: compare list

2005-11-14 Thread Brian van den Broek
Ben Bush said unto the world upon 2005-11-14 05:51: > I have four lists: > lisA=[1,2,3,4,5,6,9] > lisB=[1,6,5] > lisC=[5,6,3] > lisD=[11,14,12,15] > how can I write a function to compare lisB, lisC and lisD with lisA, if they > share two continuous elements (the order does not matter), then return

compare list

2005-11-14 Thread Ben Bush
I have four lists: lisA=[1,2,3,4,5,6,9] lisB=[1,6,5] lisC=[5,6,3] lisD=[11,14,12,15]how can I write a function to compare lisB, lisC and lisD with lisA, if they share two continuous elements (the order does not matter), then return 1, otherwise return 0. For example, lisA, lisB and lisC have 5,6 or