[Tutor] 1 to N searches in files

2012-12-02 Thread Spectral None
Hi all I have two files (File A and File B) with strings of data in them (each string on a separate line). Basically, each string in File B will be compared with all the strings in File A and the resulting output is to show a list of matched/unmatched lines and optionally to write to a third Fi

Re: [Tutor] 1 to N searches in files

2012-12-02 Thread Steven D'Aprano
On 02/12/12 19:53, Spectral None wrote: However, it seems that the results do not correctly reflect the matched/unmatched lines. As an example, if FileA contains "string1" and FileB contains multiple occurrences of "string1", it seems that the first occurrence matches correctly but subsequent "

Re: [Tutor] 1 to N searches in files

2012-12-02 Thread Dave Angel
On 12/02/2012 03:53 AM, Spectral None wrote: > Hi all > > I have two files (File A and File B) with strings of data in them (each > string on a separate line). Basically, each string in File B will be compared > with all the strings in File A and the resulting output is to show a list of > match

Re: [Tutor] how to struct.pack a unicode string?

2012-12-02 Thread Albert-Jan Roskam
>> How can I pack a unicode string using the struct module? If I simply use >> packed = struct.pack(fmt, hello) in the code below (and 'hello' is a >> unicode string), I get this: "error: argument for 's' must be a string". I >> keep reading that I have to encode it to a utf-8 bytestring, but this

Re: [Tutor] how to struct.pack a unicode string?

2012-12-02 Thread Albert-Jan Roskam
> > * some encodings are more compact than others (e.g. Latin-1 uses >   one byte per character, while UTF-32 uses four bytes per >   character). I read that performance of UTF32 is better ("UTF-32 advantage: you don't need to decode stored data to the 32-bit Unicode code point for e.g. char

Re: [Tutor] how to struct.pack a unicode string?

2012-12-02 Thread Albert-Jan Roskam
  > to make is that the transform formats are multibyte encodings (except > ASCII in UTF-8), which means the expression str(len(hello)) is using > the wrong length; it needs to use the length of the encoded string. > Also, UTF-16 and UTF-32 typically have very many null bytes. Together, > the

Re: [Tutor] how to struct.pack a unicode string?

2012-12-02 Thread Dave Angel
On 12/02/2012 08:34 AM, Albert-Jan Roskam wrote: > > > > > > > Hi Eryksun, > > Observation #1: Yes, makes perfect sense. I should have thought about that. > Observation #2: > As I emailed earlier today to Peter Otten, I thought unicode_internal means > UCS-2 or UCS-4, > depending on the size o

Re: [Tutor] FW: (no subject)

2012-12-02 Thread Ashfaq
Luke, Thanks. The generator syntax is really cool. -- Ashfaq ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor

[Tutor] Help with writing a program

2012-12-02 Thread rajesh mullings
Hello, I am trying to write a program which takes two lines of input, one called "a", and one called "b", which are both strings, then outputs the number of times a is a substring of b. If you could give me an algorithm/pseudo code of what I should do to create this program, I would greatly appreci

Re: [Tutor] Help with writing a program

2012-12-02 Thread Mark Lawrence
On 03/12/2012 03:59, rajesh mullings wrote: Hello, I am trying to write a program which takes two lines of input, one called "a", and one called "b", which are both strings, then outputs the number of times a is a substring of b. If you could give me an algorithm/pseudo code of what I should do t

Re: [Tutor] reverse diagonal

2012-12-02 Thread eryksun
On Sun, Dec 2, 2012 at 2:32 AM, Steven D'Aprano wrote: > >> ~i returns the value (-i - 1): > > Assuming certain implementation details about how integers are stored, > namely that they are two-compliment rather than one-compliment or > something more exotic. Yes, the result is platform dependent,

Re: [Tutor] Help with writing a program

2012-12-02 Thread fantasticrm
The Python version, is Python 3. On Sun, Dec 2, 2012 at 10:59 PM, rajesh mullings wrote: > Hello, I am trying to write a program which takes two lines of input, one > called "a", and one called "b", which are both strings, then outputs the > number of times a is a substring of b. If you could giv

Re: [Tutor] how to struct.pack a unicode string?

2012-12-02 Thread eryksun
On Sun, Dec 2, 2012 at 8:34 AM, Albert-Jan Roskam wrote: > > As I emailed earlier today to Peter Otten, I thought unicode_internal means > UCS-2 or UCS-4, depending on the size of sys.maxunicode? How is this related > to UTF-16 and UTF-32? UCS is the universal character set. Some highlights of th

Re: [Tutor] FW: (no subject)

2012-12-02 Thread Luke Paireepinart
On Sun, Dec 2, 2012 at 8:41 PM, Ashfaq wrote: > Luke, > > Thanks. The generator syntax is really cool. > I misspoke, the correct term is "list comprehension". A generator is something totally different! Sorry about the confusion, my fault. I type too fast sometimes :) Glad you liked it though

Re: [Tutor] Help with writing a program

2012-12-02 Thread Luke Paireepinart
There is an equivalent page in the documentation for Python 3 as well, regarding strings. This sounds a lot like a homework problem so you are unlikely to get a lot of help. You certainly won't get exact code. What have you tried so far? Where are you getting stuck? We're not here to write cod