Beginner Question : Iterators and zip



Hi group,

I have a basic question on the zip built in function.

I am writing a simple text file comparison script, that compares line
by line and character by character. The output is the original file,
with an X in place of any characters that are different.

I have managed a solution for a fixed (3) number of files, but I want
a solution of any number of input files.

The outline of my solution:

for vec in zip(vec_list[0],vec_list[1],vec_list[2]):
res = ''
for entry in zip(vec[0],vec[1],vec[2]):
if len(set(entry)) > 1:
res = res+'X'
else:
res = res+entry[0]
outfile.write(res)

So vec is a tuple containing a line from each file, and then entry is
a tuple containg a character from each line.

2 questions
1) What is the general solution. Using zip in this way looks wrong. Is
there another function that does what I want
2) I am using set to remove any repeated characters. Is there a
"better" way ?

Any other comments/suggestions appreciated.

Thanks,

Steven





.



Relevant Pages

  • Re: Beginner Question : Iterators and zip
    ... I have a basic question on the zip built in function. ... I am writing a simple text file comparison script, ... by line and character by character. ... So you'd better pad your sequences to make them as long as the longer ...
    (comp.lang.python)
  • Re: Beginner Question : Iterators and zip
    ... I have a basic question on the zip built in function. ... I am writing a simple text file comparison script, ... by line and character by character. ... don't rebuild the output line char by char. ...
    (comp.lang.python)
  • Re: Beginner Question : Iterators and zip
    ... I have a basic question on the zip built in function. ... I am writing a simple text file comparison script, ... by line and character by character. ... a tuple containg a character from each line. ...
    (comp.lang.python)
  • Re: Comic book/comic strip deaths, resurrection included
    ... of the art form for death to be temporary. ... can anyone answer the basic question: ... Not a comic strip character, but Sherlock Holmes died at Reichenbach Falls, and Conan Doyle reluctantly brought him back due ...
    (rec.arts.comics.strips)
  • [opensuse] Activating routes
    ... This is a pretty basic question and I am almost embarrassed to ask. ... looking for a means to activate this route without having to run ... "Be more concerned with your character than with your reputation. ...
    (SuSE)