On Tuesday, 14 April 2015 09:54:46 UTC-4, Michiel Overtoom wrote:
> On Apr 14, 2015, at 15:34, Pippo wrote:
>
> > How can I use dictionary to save the following information?
>
> What a curious question. The purpose of a dictionary is not to save
> information, but to store data as a key -> valu
On Tue, 14 Apr 2015 11:34 pm, Pippo wrote:
> How can I use dictionary to save the following information?
>
> #C[Health]
> #P[Information]
> #ST[genetic information]
> #C[oral | (recorded in (any form | medium))]
> #C[Is created or received by]
> #A[health care provider | health plan | public heal
On Apr 14, 2015, at 15:34, Pippo wrote:
> How can I use dictionary to save the following information?
What a curious question. The purpose of a dictionary is not to save
information, but to store data as a key -> value mapping:
telbook = {}
telbook["jan"] = "0627832873"
telbook["ma
How can I use dictionary to save the following information?
#C[Health]
#P[Information]
#ST[genetic information]
#C[oral | (recorded in (any form | medium))]
#C[Is created or received by]
#A[health care provider | health plan | public health authority | employer |
life insurer | school | universit
Chris Jones wrote:
> On Fri, Jan 22, 2010 at 05:07:13PM EST, Arnaud Delobelle wrote:
>
> [..]
>
>> import codecs
>> from collections import defaultdict
>>
>> tcounters = defaultdict(int)
>> f = codecs.open('/home/gavron/git/screen/src/screen.c', 'r', "utf-8")
>>
>> for c in f.read():
>> tcoun
On Sat, Jan 23, 2010 at 02:45:41AM EST, Terry Reedy wrote:
> On 1/22/2010 9:58 PM, Chris Jones wrote:
>> Do you mean I should just read the file one character at a time?
>
> Whoops, my misdirection (you can .read(1), but this is s l o w.
> I meant to suggest processing it a char at a time.
R
On 1/22/2010 9:58 PM, Chris Jones wrote:
On Fri, Jan 22, 2010 at 08:46:35PM EST, Terry Reedy wrote:
Do you mean I should just read the file one character at a time?
Whoops, my misdirection (you can .read(1), but this is s l o w.
I meant to suggest processing it a char at a time.
1. If
On Fri, Jan 22, 2010 at 08:46:35PM EST, Terry Reedy wrote:
> On 1/22/2010 4:47 PM, Chris Jones wrote:
>> I was writing a script that counts occurrences of characters in source code
>> files:
>>
>> #!/usr/bin/python
>> import codecs
>> tcounters = {}
>> f = codecs.open('/home/gavron/git/screen/src/
On 1/22/2010 4:47 PM, Chris Jones wrote:
I was writing a script that counts occurrences of characters in source code
files:
#!/usr/bin/python
import codecs
tcounters = {}
f = codecs.open('/home/gavron/git/screen/src/screen.c', 'r', "utf-8")
for uline in f:
lline = []
for char in uline[:-1
On Fri, Jan 22, 2010 at 05:07:13PM EST, Arnaud Delobelle wrote:
[..]
> import codecs
> from collections import defaultdict
>
> tcounters = defaultdict(int)
> f = codecs.open('/home/gavron/git/screen/src/screen.c', 'r', "utf-8")
>
> for c in f.read():
> tcounters[c] += 1
>
> for c, n in tco
Chris Jones writes:
> I was writing a script that counts occurrences of characters in source
> code files:
>
> #!/usr/bin/python
> import codecs
> tcounters = {}
> f = codecs.open('/home/gavron/git/screen/src/screen.c', 'r', "utf-8")
> for uline in f:
> lline = []
> for char in uline[:-1]:
>
I was writing a script that counts occurrences of characters in source code
files:
#!/usr/bin/python
import codecs
tcounters = {}
f = codecs.open('/home/gavron/git/screen/src/screen.c', 'r', "utf-8")
for uline in f:
lline = []
for char in uline[:-1]:
lline += [char]
counters = {}
for
André a écrit :
(snip)
you don't need to use pattern.items()...
Here is something I use (straight cut-and-paste):
def parse_single_line(self, line):
'''Parses a given line to see if it match a known pattern'''
for name in self.patterns:
result = self.patterns[nam
John Machin schrieb:
No, "complicated" is more related to unused features. In
the case of using an aeroplane to transport 3 passengers 10 km along
the autobahn, you aren't using the radar, wheel-retractability, wings,
pressurised cabin, etc. In your original notion of using a dict in
your lexer,
John Machin wrote:
> On Nov 25, 4:38 am, Thomas Mlynarczyk <[EMAIL PROTECTED]>
[...]
>>> Judging which of two structures is "simpler" should not be independent
>>> of those requirements. I don't see a role for intuition in this
>>> process.
>> Maybe I should have said "upon first sight" / "judging
On Nov 25, 4:38 am, Thomas Mlynarczyk <[EMAIL PROTECTED]>
wrote:
> John Machin schrieb:
>
> > Rephrasing for clarity: Don't use a data structure that is more
> > complicated than that indicated by your requirements.
>
> Could you please define "complicated" in this context? In terms of
> characters
John Machin schrieb:
Rephrasing for clarity: Don't use a data structure that is more
complicated than that indicated by your requirements.
Could you please define "complicated" in this context? In terms of
characters to type and reading, the dict is surely simpler. But I
suppose that under t
Dennis Lee Bieber schrieb:
Is "[ ( name, regex ), ... ]" really "simpler" than "{ name: regex, ...
}"? Intuitively, I would consider the dictionary to be the simpler
structure.
Why, when you aren't /using/ the name to retrieve the expression...
So as soon as I start retrieving a re
On Mon, 24 Nov 2008 00:46:42 +0100, Gilles Ganault wrote:
> On Sun, 23 Nov 2008 23:18:06 +, MRAB <[EMAIL PROTECTED]>
> wrote:
>>A list is an ordered collection of items. Each item can be anything: a
>>string, an integer, a dictionary, a tuple, a list...
>
> Yup, learned something new today. N
On Sun, 23 Nov 2008 23:18:06 +, MRAB <[EMAIL PROTECTED]>
wrote:
>A list is an ordered collection of items. Each item can be anything: a
>string, an integer, a dictionary, a tuple, a list...
Yup, learned something new today. Naively, I though a list was
index=value, where value=a single piece
Gilles Ganault wrote:
On Sun, 23 Nov 2008 17:55:48 +, Arnaud Delobelle
<[EMAIL PROTECTED]> wrote:
But there is no reason why you should use a dictionary; just use a list
of key-value pairs:
Thanks for the tip. I didn't know it was possible to use arrays to
hold more than one value. Actuall
On Sun, 23 Nov 2008 17:55:48 +, Arnaud Delobelle
<[EMAIL PROTECTED]> wrote:
>But there is no reason why you should use a dictionary; just use a list
>of key-value pairs:
Thanks for the tip. I didn't know it was possible to use arrays to
hold more than one value. Actually, it's a better solutio
On Nov 24, 7:49 am, Thomas Mlynarczyk <[EMAIL PROTECTED]>
wrote:
> John Machin schrieb:
>
> > General tip: Don't us a data structure that is more complicated than
> > what you need.
>
> Is "[ ( name, regex ), ... ]" really "simpler" than "{ name: regex, ...}"?
> Intuitively, I would consider the d
On Nov 24, 7:48 am, John Machin <[EMAIL PROTECTED]> wrote:
> On Nov 24, 5:36 am, Terry Reedy <[EMAIL PROTECTED]> wrote:
>
> > print name + '#' + regex
>
> Perhaps you meant:
> print key + "#" + regex.pattern
I definitely meant:
print name + '#' + regex.pattern
--
http://mail.python.org/mailm
On Nov 23, 1:40 pm, Gilles Ganault <[EMAIL PROTECTED]> wrote:
> Hello
>
> After downloading a web page, I need to search for several patterns,
> and if found, extract information and put them into a database.
>
> To avoid a bunch of "if m", I figured maybe I could use a dictionary
> to hold the pat
John Machin schrieb:
General tip: Don't us a data structure that is more complicated than
what you need.
Is "[ ( name, regex ), ... ]" really "simpler" than "{ name: regex, ...
}"? Intuitively, I would consider the dictionary to be the simpler
structure.
Greetings,
Thomas
--
Ce n'est pas
On Nov 24, 5:36 am, Terry Reedy <[EMAIL PROTECTED]> wrote:
> Gilles Ganault wrote:
> > Hello
>
> > After downloading a web page, I need to search for several patterns,
> > and if found, extract information and put them into a database.
>
> > To avoid a bunch of "if m", I figured maybe I could use a
On Nov 24, 6:55 am, Gilles Ganault <[EMAIL PROTECTED]> wrote:
> On Sun, 23 Nov 2008 17:55:48 +, Arnaud Delobelle
>
> <[EMAIL PROTECTED]> wrote:
> >But there is no reason why you should use a dictionary; just use a list
> >of key-value pairs:
>
> >patterns = [
> > ("pattern1", re.compile(">.+
On Sun, Nov 23, 2008 at 2:55 PM, Gilles Ganault <[EMAIL PROTECTED]> wrote:
> On Sun, 23 Nov 2008 17:55:48 +, Arnaud Delobelle
> <[EMAIL PROTECTED]> wrote:
> >But there is no reason why you should use a dictionary; just use a list
> >of key-value pairs:
> >
> >patterns = [
> >("pattern1", r
2008/11/23 Gilles Ganault <[EMAIL PROTECTED]>
> Hello
>
> After downloading a web page, I need to search for several patterns,
> and if found, extract information and put them into a database.
>
> To avoid a bunch of "if m", I figured maybe I could use a dictionary
> to hold the patterns, and loop
On Sun, 23 Nov 2008 17:55:48 +, Arnaud Delobelle
<[EMAIL PROTECTED]> wrote:
>But there is no reason why you should use a dictionary; just use a list
>of key-value pairs:
>
>patterns = [
>("pattern1", re.compile(">.+?.+?>(.+?)"),
Thanks for the tip, but... I thought that lists could only us
Gilles Ganault wrote:
Hello
After downloading a web page, I need to search for several patterns,
and if found, extract information and put them into a database.
To avoid a bunch of "if m", I figured maybe I could use a dictionary
to hold the patterns, and loop through it:
Good idea.
import r
Gilles Ganault <[EMAIL PROTECTED]> writes:
> Hello
>
> After downloading a web page, I need to search for several patterns,
> and if found, extract information and put them into a database.
>
> To avoid a bunch of "if m", I figured maybe I could use a dictionary
> to hold the patterns, and loop th
Hello
After downloading a web page, I need to search for several patterns,
and if found, extract information and put them into a database.
To avoid a bunch of "if m", I figured maybe I could use a dictionary
to hold the patterns, and loop through it:
==
pattern = {}
pattern["pattern1"] = ">.
34 matches
Mail list logo