[EMAIL PROTECTED] a écrit :
> On Oct 27, 6:42 am, Karthik Gurusamy <[EMAIL PROTECTED]> wrote:
>
>>On Oct 26, 9:29 pm, Frank Stutzman <[EMAIL PROTECTED]> wrote:
>>
>>
>>
>>
>>>My apologies in advance, I'm new to python
>>
>>>Say, I have a dictionary that looks like this:
>>
>>>record={'BAT': '14.4'
On Oct 27, 6:42 am, Karthik Gurusamy <[EMAIL PROTECTED]> wrote:
> On Oct 26, 9:29 pm, Frank Stutzman <[EMAIL PROTECTED]> wrote:
>
>
>
> > My apologies in advance, I'm new to python
>
> > Say, I have a dictionary that looks like this:
>
> >record={'BAT': '14.4', 'USD': '24', 'DIF': '45', 'OAT': '16'
Steven D'Aprano a écrit :
(snip)
> eval("{" + reduce(lambda x,y: y+', '+x, [mo.group(1) for mo in __import__
> ('re').finditer(r"('E.*?'\s*:\s*'.*?'),?", str(record))], "") + "}")
Maman !
Steven, you choose the wrong language. You definitively want Perl !
--
http://mail.python.org/mailman/listin
Martin v. Löwis a écrit :
>>>egt = {}
>>>for key in record:
>>> if key.startswith('E'):
>>> egt[key] = record[key]
>>
>>I actually had come up with something like this, but thought it wasn't
>>quite as pythonish as it should be. It is certainly much more readable
>>to a neophyte to python.
On Oct 27, 8:58 am, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote:
> On Sat, 27 Oct 2007 05:23:30 -0700, bearophileHUGS wrote:
> > My take too :-)
>
> > dict(item for item in record.iteritems() if item[0][0] == 'E')
>
> ``s.startswith('E')`` is a little safer than ``s[0] == 'E'`` as the former
>> egt = {}
>> for key in record:
>>if key.startswith('E'):
>>egt[key] = record[key]
>
> I actually had come up with something like this, but thought it wasn't
> quite as pythonish as it should be. It is certainly much more readable
> to a neophyte to python.
My recommendation: forge
Marc 'BlackJack' Rintsch>``s.startswith('E')`` is a little safer than
``s[0] == 'E'`` as the former returns `False` if `s` is empty while
the latter raises an `IndexError`.<
Thank you.
In this problem if there is an empty key in the record dict then maybe
it's better to raise an IndexError, becaus
Wow, what a great group! Lots of useful and kind suggestions to what I was
sure was a fairly dumb question. A few comments on some selected suggestions
(but I appreciate all of them)
Edward Kozlowski wrote:
> egt = {}
> for key in record:
>if key.startswith('E'):
>egt[key] = record[
On Sat, 27 Oct 2007 04:29:51 +, Frank Stutzman wrote:
> My apologies in advance, I'm new to python
>
> Say, I have a dictionary that looks like this:
>
> record={'BAT': '14.4', 'USD': '24', 'DIF': '45', 'OAT': '16',
> 'FF': '3.9', 'C3': '343', 'E4': '1157', 'C1': '339', 'E6':
>
On Sat, 27 Oct 2007 05:23:30 -0700, bearophileHUGS wrote:
> My take too :-)
>
> dict(item for item in record.iteritems() if item[0][0] == 'E')
``s.startswith('E')`` is a little safer than ``s[0] == 'E'`` as the former
returns `False` if `s` is empty while the latter raises an `IndexError`.
Ciao
My take too :-)
dict(item for item in record.iteritems() if item[0][0] == 'E')
Bye,
bearophile
--
http://mail.python.org/mailman/listinfo/python-list
Frank Stutzman a écrit :
> My apologies in advance, I'm new to python
>
> Say, I have a dictionary that looks like this:
>
> record={'BAT': '14.4', 'USD': '24', 'DIF': '45', 'OAT': '16',
> 'FF': '3.9', 'C3': '343', 'E4': '1157', 'C1': '339',
> 'E6': '1182', 'RPM': '996', 'C6': '31
On Oct 27, 1:16 am, Frank Millman <[EMAIL PROTECTED]> wrote:
> On Oct 27, 8:02 am, Frank Millman <[EMAIL PROTECTED]> wrote:
>
> > > This should work -
>
> > > egt = dict([i for i in d.items() if i[0].startswith('E')])
>
> > Of course I meant record.items(), not d.items(). Sorry.
>
> > Frank
>
> On
On Oct 27, 8:02 am, Frank Millman <[EMAIL PROTECTED]> wrote:
> > This should work -
>
> > egt = dict([i for i in d.items() if i[0].startswith('E')])
>
> Of course I meant record.items(), not d.items(). Sorry.
>
> Frank
On reflection, although my solution is a bit shorter than some others,
it may n
>
> This should work -
>
> egt = dict([i for i in d.items() if i[0].startswith('E')])
>
Of course I meant record.items(), not d.items(). Sorry.
Frank
--
http://mail.python.org/mailman/listinfo/python-list
Frank Stutzman wrote:
> My apologies in advance, I'm new to python
>
> Say, I have a dictionary that looks like this:
>
> record={'BAT': '14.4', 'USD': '24', 'DIF': '45', 'OAT': '16',
> 'FF': '3.9', 'C3': '343', 'E4': '1157', 'C1': '339',
> 'E6': '1182', 'RPM': '996', 'C6': '311',
> On Behalf Of Edward Kozlowski
> I think this should do the trick. There's probably something
> more concise than this, but I can't think of it at the moment.
>
> egt = {}
> for key in record:
> if key.startswith('E'):
> egt[key] = record[key]
Not much more concise, but another way
On Oct 26, 9:29 pm, Frank Stutzman <[EMAIL PROTECTED]> wrote:
> My apologies in advance, I'm new to python
>
> Say, I have a dictionary that looks like this:
>
> record={'BAT': '14.4', 'USD': '24', 'DIF': '45', 'OAT': '16',
> 'FF': '3.9', 'C3': '343', 'E4': '1157', 'C1': '339',
> 'E
On Oct 26, 11:29 pm, Frank Stutzman <[EMAIL PROTECTED]>
wrote:
> My apologies in advance, I'm new to python
>
> Say, I have a dictionary that looks like this:
>
> record={'BAT': '14.4', 'USD': '24', 'DIF': '45', 'OAT': '16',
> 'FF': '3.9', 'C3': '343', 'E4': '1157', 'C1': '339',
> '
19 matches
Mail list logo