Re: How to enter multiple, similar, dictionaries?

2023-12-11 Thread Piergiorgio Sartor via Python-list
On 11/12/2023 16.16, Chris Green wrote: Is there a way to abbreviate the following code somehow? lv = {'dev':'bbb', 'input':'1', 'name':'Leisure volts'} sv = {'dev':'bbb', 'input':'0', 'name':'Starter volts'} la = {'dev':'bbb', 'input':'2', 'name':'Leisure Amps'} sa = {'dev':

Re: How to enter multiple, similar, dictionaries?

2023-12-11 Thread Chris Green via Python-list
= {'dev':'bbb', 'input':'3', 'name':'Starter Amps'} > >> bv = {'dev':'adc2', 'input':0, 'name':'BowProp Volts'} > >> > >> It's effectively a 'tab

Re: How to enter multiple, similar, dictionaries?

2023-12-11 Thread Jon Ribbens via Python-list
7;3', 'name':'Starter Amps'} >> bv = {'dev':'adc2', 'input':0, 'name':'BowProp Volts'} >> >> It's effectively a 'table' with columns named 'dev', 'input' and >

Re: How to enter multiple, similar, dictionaries?

2023-12-11 Thread MRAB via Python-list
tarter Amps'} bv = {'dev':'adc2', 'input':0, 'name':'BowProp Volts'} It's effectively a 'table' with columns named 'dev', 'input' and 'name' and I want to access the values of the table using the

Re: How to enter multiple, similar, dictionaries?

2023-12-11 Thread Grant Edwards via Python-list
On 2023-12-11, Chris Green via Python-list wrote: > Is there a way to abbreviate the following code somehow? > > lv = {'dev':'bbb', 'input':'1', 'name':'Leisure volts'} > sv = {'dev':'bbb', 'input':'0', 'name':'Starter volts'} > la = {'dev':'bbb', 'input':'2', 'name':'Leisure Amps'} >

Re: How to enter multiple, similar, dictionaries?

2023-12-11 Thread Chris Green via Python-list
= {'dev':'adc2', 'input':0, 'name':'BowProp Volts'} > > It's effectively a 'table' with columns named 'dev', 'input' and > 'name' and I want to access the values of the table using the variable

How to enter multiple, similar, dictionaries?

2023-12-11 Thread Chris Green via Python-list
Is there a way to abbreviate the following code somehow? lv = {'dev':'bbb', 'input':'1', 'name':'Leisure volts'} sv = {'dev':'bbb', 'input':'0', 'name':'Starter volts'} la = {'dev':'bbb', 'input':'2', 'name':'Leisure Amps'} sa = {'dev':'bbb', 'input':'3', 'name':'Starter Amps'}

Re: Behaviour of pop() for dictionaries

2021-06-15 Thread dn via Python-list
at I know I am going to have to look at > the documentation for dequeue when I want to use it. For lists, sets and > dictionaries, I don't expect to look at the documentation and pop() > seemed a good bet for what I wanted to do. "What I expect" (aka 'dim/dusty recollecti

Re: Behaviour of pop() for dictionaries

2021-06-15 Thread BlindAnagram
a problem, you're going to love using deques with their 'popping from the left' and 'popping from the right' concepts! I think the difference here is that I know I am going to have to look at the documentation for dequeue when I want to use it. For lists, sets and dictiona

Re: Behaviour of pop() for dictionaries

2021-06-15 Thread BlindAnagram
On 15/06/2021 01:36, Terry Reedy wrote: On 6/14/2021 5:18 PM, BlindAnagram wrote: I believe that consistency in how methods common to different types work is useful since it adds to the coherence of the language as a whole and avoids the need to remember special cases. Each collection class

Re: Behaviour of pop() for dictionaries

2021-06-15 Thread Cameron Simpson
On 14Jun2021 09:39, BlindAnagram wrote: >However, d.pop(key, [default]) returns the value (or the default) and >consistency with other pops (a good thing in my view) would suggest >that d.pop() could return a random value, which would serve my purpose >when there is only one element. If you do

Re: Behaviour of pop() for dictionaries

2021-06-14 Thread Terry Reedy
On 6/14/2021 5:18 PM, BlindAnagram wrote: I believe that consistency in how methods common to different types work is useful since it adds to the coherence of the language as a whole and avoids the need to remember special cases. Each collection class *is* a special case, and pop has to be ad

Re: Behaviour of pop() for dictionaries

2021-06-14 Thread dn via Python-list
On 15/06/2021 09.18, BlindAnagram wrote: > On 14/06/2021 20:43, Chris Angelico wrote: >> On Tue, Jun 15, 2021 at 5:41 AM BlindAnagram ... > No it isn't hard to use popitem() but it evidently proved hard for me to > remember that it was there. If that's a problem, you're going to love using deques

Re: Behaviour of pop() for dictionaries

2021-06-14 Thread BlindAnagram
my purpose when there is only one element. Is this actually important or are you just looking for a meaningless "inconsistency"? Dictionaries are fundamentally different from lists. Is it really that hard to use popitem? No I am not looking for meaningless inconsistency - just the o

Re: Behaviour of pop() for dictionaries

2021-06-14 Thread Chris Angelico
is only one element. > Is this actually important or are you just looking for a meaningless "inconsistency"? Dictionaries are fundamentally different from lists. Is it really that hard to use popitem? ChrisA -- https://mail.python.org/mailman/listinfo/python-list

Re: Behaviour of pop() for dictionaries

2021-06-14 Thread BlindAnagram
we don't have d.pop() for dictionaries? My guess is because it's not generally useful to get an returns the value arbitrary value from a dict without its corresponding key. Hence the existence of popitem(). However, d.pop(key, [default]) returns the value (or the default) and c

Behaviour of pop() for dictionaries

2021-06-14 Thread BlindAnagram
The pop() method exists for five mainstream data items and shows a range of different behaviours for each of them. But, of the five, pop for dictionaries is the only one for which the first parameter is required and this makes d.pop() for dictionaries an error rather than doing something

Re: Behaviour of pop() for dictionaries

2021-06-14 Thread Stestagg
o hold only one item? > > v = d.popitem()[1] > > > More importantly, is there a good reason why we don't have d.pop() for > > dictionaries? > > My guess is because it's not generally useful to get an arbitrary > value from a dict without its corresponding

Re: Behaviour of pop() for dictionaries

2021-06-14 Thread Greg Ewing
On 14/06/21 4:19 am, BlindAnagram wrote: Am I missing the obvious way to obtain the value (or the key) from a dictionary that is known to hold only one item? v = d.popitem()[1] More importantly, is there a good reason why we don't have d.pop() for dictionaries? My guess is because it&

Re: list of dictionaries search using kwargs

2020-12-07 Thread Marco Sulla
On Mon, 7 Dec 2020 at 23:35, Larry Martell wrote: > > On Mon, Dec 7, 2020 at 5:29 PM Marco Sulla > wrote: > > > > You can return dictionaries that returns True if > > > > (a.items() & kwargs.items()) == kwargs.items() > > > > when `a` is one of

Re: list of dictionaries search using kwargs

2020-12-07 Thread MRAB
On 2020-12-07 22:06, Larry Martell wrote: I have a class that has an object that contains a list of dicts. I want to have a class method that takes a variable number of key/value pairs and searches the list and returns the item that matches the arguments. If I know the key value pairs I can do s

Re: list of dictionaries search using kwargs

2020-12-07 Thread Larry Martell
On Mon, Dec 7, 2020 at 5:42 PM Matt Wheeler wrote: > > for item in self.data: > if all(item[k] == v for k,v in kwargs.items()): > return item > > Or > > return [item for item in self.data if all(item[k] == v for k,v in > kwargs.items())] > > to return all matches > > Beware though tha

Re: list of dictionaries search using kwargs

2020-12-07 Thread Matt Wheeler
for item in self.data:     if all(item[k] == v for k,v in kwargs.items()):         return item Or return [item for item in self.data if all(item[k] == v for k,v in kwargs.items())] to return all matches Beware though that either of these will be slow if your list of dicts is large. If the list

Re: list of dictionaries search using kwargs

2020-12-07 Thread Larry Martell
On Mon, Dec 7, 2020 at 5:29 PM Marco Sulla wrote: > > You can return dictionaries that returns True if > > (a.items() & kwargs.items()) == kwargs.items() > > when `a` is one of your dicts. But what is passed in kwargs will not necessarily have values for all of the keys an

Re: list of dictionaries search using kwargs

2020-12-07 Thread Marco Sulla
You can return dictionaries that returns True if (a.items() & kwargs.items()) == kwargs.items() when `a` is one of your dicts. -- https://mail.python.org/mailman/listinfo/python-list

list of dictionaries search using kwargs

2020-12-07 Thread Larry Martell
I have a class that has an object that contains a list of dicts. I want to have a class method that takes a variable number of key/value pairs and searches the list and returns the item that matches the arguments. If I know the key value pairs I can do something like this: instance = next(item fo

Re: How to expand and flatten a nested of list of dictionaries of varied lengths?

2020-10-18 Thread dn via Python-list
If I may, a couple of items of list-etiquette (polite behavior), as I understand them: 1 please reply to the list (cf only myself) because @Mats (who responded earlier) and others on this list are much smarter than me, and might be able to help you more quickly 2 top-posting seems to take the fo

Re: How to expand and flatten a nested of list of dictionaries of varied lengths?

2020-10-18 Thread Mats Wichmann
On 10/18/20 2:09 PM, Shaozhong SHI wrote: > Even worse is that, in some cases, an addition called serviceRatings as a > key occur with new data unexpectedly. > > How to produce a robust Python/Panda script to coping with all these? > > Regards, > > David > > u'historicRatings': [{u'overall': {u

Re: How to expand and flatten a nested of list of dictionaries of varied lengths?

2020-10-18 Thread dn via Python-list
On 19/10/2020 09:09, Shaozhong SHI wrote: Even worse is that, in some cases, an addition called serviceRatings as a key occur with new data unexpectedly. "Even worse" than what? Do you need to keep a list of acceptable/applicable/available keys? (and reject or deal with others in some alternat

How to expand and flatten a nested of list of dictionaries of varied lengths?

2020-10-18 Thread Shaozhong SHI
Even worse is that, in some cases, an addition called serviceRatings as a key occur with new data unexpectedly. How to produce a robust Python/Panda script to coping with all these? Regards, David u'historicRatings': [{u'overall': {u'keyQuestionRatings': [{u'name': u'Safe', u'rating': u'Require

Re: dictionaries an matrices

2020-09-16 Thread joseph pareti
you can use the following: (change the matrices as it suits your app): import numpy as np def set_params(w, b): params = {"w0": w[0], "w1": w[1] , "w2": w[2], "w3": w[3], "w4": w[4], "b": b} return params w = np.random.randn((5)) b = 1 params = set_params(w, b) for i in range(5)

dictionaries an matrices

2020-09-16 Thread Ing Diegohl
Good morning everyone I would like to know if i can to create a dictionary with two matrices, where every element of the first matrix corresponds to dictionary's keys and the elements of the second matrix will be the values every key. thanks -- https://mail.python.org/mailman/listinfo/python-lis

Re: PEP Idea: Multi-get for lists/tuples and dictionaries (inspired in NumPy)

2020-03-19 Thread Marco Sulla
On Thu, 19 Mar 2020 at 16:46, Peter J. Holzer wrote: > This is similar to algebraic expressions: Have you ever tried to read a > mathematical paper from before the time the current notation (which we > Long, convoluted > sentences instead of what can now be written as a short formula. ...yes, and

Re: PEP Idea: Multi-get for lists/tuples and dictionaries (inspired in NumPy)

2020-03-19 Thread MRAB
On 2020-03-19 15:17, Musbur wrote: Hello, either it's me or everybody else who's missing the point. I understand the OP's proposal like this: dict[set] == {k: dict[k] for k in set} list[iterable] == [list[i] for i in iterable] Am I right? "Iterable" is too broad because it includes tuples an

Re: PEP Idea: Multi-get for lists/tuples and dictionaries (inspired in NumPy)

2020-03-19 Thread Rhodri James
On 19/03/2020 14:47, Peter J. Holzer wrote: On 2020-03-19 14:24:35 +, Rhodri James wrote: On 19/03/2020 13:00, Peter J. Holzer wrote: It's more compact, especially, if "d" isn't a one-character variable, but an expression: fname, lname = db[people].employee.object.get(pk=1234)[['firs

Re: PEP Idea: Multi-get for lists/tuples and dictionaries (inspired in NumPy)

2020-03-19 Thread Chris Angelico
On Fri, Mar 20, 2020 at 2:46 AM Peter J. Holzer wrote: > > A good language has a small core and extensibility via > > libraries. > > This would actually be a feature of the (standard) library. I think the line kinda blurs here. This would be a feature of a core data type, and in CPython, it would

RE: PEP Idea: Multi-get for lists/tuples and dictionaries (inspired in NumPy)

2020-03-19 Thread David Raymond
For dictionaries it'd even be more useful: d = { 'first_name': 'Frances', 'last_name': 'Allen', 'email': 'fal...@ibm.com' } fname, lname = d[['first_name', 'last_name']] Why no

Re: PEP Idea: Multi-get for lists/tuples and dictionaries (inspired in NumPy)

2020-03-19 Thread Chris Angelico
On Fri, Mar 20, 2020 at 2:37 AM Terry Reedy wrote: > > On 3/18/2020 10:28 PM, Santiago Basulto wrote: > > > For dictionaries it'd even be more useful: > > d = { > > 'first_name': 'Frances', > > &

Re: PEP Idea: Multi-get for lists/tuples and dictionaries (inspired in NumPy)

2020-03-19 Thread Peter J. Holzer
On 2020-03-19 08:05:18 -0700, Dan Stromberg wrote: > On Thu, Mar 19, 2020 at 7:47 AM Peter J. Holzer wrote: > > On 2020-03-19 14:24:35 +, Rhodri James wrote: > > > On 19/03/2020 13:00, Peter J. Holzer wrote: > > > > It's more compact, especially, if "d" isn't a one-character variable, > > > >

Re: PEP Idea: Multi-get for lists/tuples and dictionaries (inspired in NumPy)

2020-03-19 Thread Ethan Furman
On 03/19/2020 02:09 AM, Terry Reedy wrote: On 3/18/2020 10:28 PM, Santiago Basulto wrote: For dictionaries it'd even be more useful: d = { 'first_name': 'Frances', 'last_name': 'Allen', 'email': &#x

Re: PEP Idea: Multi-get for lists/tuples and dictionaries (inspired in NumPy)

2020-03-19 Thread Terry Reedy
On 3/18/2020 10:28 PM, Santiago Basulto wrote: For dictionaries it'd even be more useful: d = { 'first_name': 'Frances', 'last_name': 'Allen', 'email': 'fal...@ibm.com' } fname, lname

Re: PEP Idea: Multi-get for lists/tuples and dictionaries (inspired in NumPy)

2020-03-19 Thread Musbur
Hello, either it's me or everybody else who's missing the point. I understand the OP's proposal like this: dict[set] == {k: dict[k] for k in set} list[iterable] == [list[i] for i in iterable] Am I right? -- https://mail.python.org/mailman/listinfo/python-list

Re: PEP Idea: Multi-get for lists/tuples and dictionaries (inspired in NumPy)

2020-03-19 Thread Pieter van Oostrum
Py? I think multi indexing > alone would be huge addition. A few examples: > > For lists and tuples: > >>> l = ['a', 'b', 'c'] > >>> l[[0, -1]] > ['a', 'c'] > > For dictionaries it&#

Re: PEP Idea: Multi-get for lists/tuples and dictionaries (inspired in NumPy)

2020-03-19 Thread Dan Stromberg
On Thu, Mar 19, 2020 at 7:47 AM Peter J. Holzer wrote: > On 2020-03-19 14:24:35 +, Rhodri James wrote: > > On 19/03/2020 13:00, Peter J. Holzer wrote: > > > It's more compact, especially, if "d" isn't a one-character variable, > > > but an expression: > > > > > > fname, lname = > db[peop

Re: PEP Idea: Multi-get for lists/tuples and dictionaries (inspired in NumPy)

2020-03-19 Thread Peter J. Holzer
On 2020-03-19 14:24:35 +, Rhodri James wrote: > On 19/03/2020 13:00, Peter J. Holzer wrote: > > It's more compact, especially, if "d" isn't a one-character variable, > > but an expression: > > > > fname, lname = db[people].employee.object.get(pk=1234)[['first_name', > > 'last_name']] > >

Re: PEP Idea: Multi-get for lists/tuples and dictionaries (inspired in NumPy)

2020-03-19 Thread Rhodri James
On 19/03/2020 13:00, Peter J. Holzer wrote: On 2020-03-19 18:22:34 +1300, DL Neil via Python-list wrote: On 19/03/20 3:28 PM, Santiago Basulto wrote: myself missing A LOT features from NumPy, like fancy indexing or boolean arrays. So, has it ever been considered to bake into Python's builtin li

Re: PEP Idea: Multi-get for lists/tuples and dictionaries (inspired in NumPy)

2020-03-19 Thread Peter J. Holzer
t and > > dictionary types functionality inspired by NumPy? I think multi indexing > > alone would be huge addition. A few examples: > > For lists and tuples: > > >>> l = ['a', 'b', 'c'] > > >>> l[[0, -1]] &g

Re: PEP Idea: Multi-get for lists/tuples and dictionaries (inspired in NumPy)

2020-03-18 Thread DL Neil via Python-list
be huge addition. A few examples: For lists and tuples: >>> l = ['a', 'b', 'c'] >>> l[[0, -1]] ['a', 'c'] For dictionaries it'd even be more useful: d = { 'first_name': 'Frances&

PEP Idea: Multi-get for lists/tuples and dictionaries (inspired in NumPy)

2020-03-18 Thread Santiago Basulto
lists and tuples: >>> l = ['a', 'b', 'c'] >>> l[[0, -1]] ['a', 'c'] For dictionaries it'd even be more useful: d = { 'first_name': 'Frances', 'last_name': 'Allen

Re: Help on dictionaries...

2020-01-29 Thread Souvik Dutta
How do I connect it with my dictionary On Thu, Jan 30, 2020, 7:03 AM Tim Chase wrote: > On 2020-01-30 06:44, Souvik Dutta wrote: > > Hey I was thinking how I can save a dictionary in python(obviously) > > so that the script is rerun it automatically loads the dictionary. > > This is almost exact

Re: Help on dictionaries...

2020-01-29 Thread MRAB
On 2020-01-30 01:51, Michael Torrie wrote: On 1/29/20 6:14 PM, Souvik Dutta wrote: Hey I was thinking how I can save a dictionary in python(obviously) so that the script is rerun it automatically loads the dictionary. You could use the pickle module for that. See the python.org documentation o

Re: Help on dictionaries...

2020-01-29 Thread Souvik Dutta
Thank you all. On Thu, Jan 30, 2020, 7:25 AM DL Neil via Python-list < python-list@python.org> wrote: > On 30/01/20 2:14 PM, Souvik Dutta wrote: > > Hey I was thinking how I can save a dictionary in python(obviously) so > that > > the script is rerun it automatically loads the dictionary. > > > P

Re: Help on dictionaries...

2020-01-29 Thread Tim Chase
On 2020-01-30 06:44, Souvik Dutta wrote: > Hey I was thinking how I can save a dictionary in python(obviously) > so that the script is rerun it automatically loads the dictionary. This is almost exactly what the "dbm" (nee "anydbm") module does, but persisting the dictionary out to the disk: im

Re: Help on dictionaries...

2020-01-29 Thread DL Neil via Python-list
On 30/01/20 2:14 PM, Souvik Dutta wrote: Hey I was thinking how I can save a dictionary in python(obviously) so that the script is rerun it automatically loads the dictionary. Perhaps a YAML or JSON file (which follow a very similar format and structure to Python dicts), or a 'NoSQL' database

Re: Help on dictionaries...

2020-01-29 Thread Michael Torrie
On 1/29/20 6:14 PM, Souvik Dutta wrote: > Hey I was thinking how I can save a dictionary in python(obviously) so that > the script is rerun it automatically loads the dictionary. You could use the pickle module for that. See the python.org documentation on pickle. Alternatively you could use a js

Help on dictionaries...

2020-01-29 Thread Souvik Dutta
Hey I was thinking how I can save a dictionary in python(obviously) so that the script is rerun it automatically loads the dictionary. -- https://mail.python.org/mailman/listinfo/python-list

RE: How to sort over dictionaries

2018-08-30 Thread David Raymond
al Message- From: Python-list [mailto:python-list-bounces+david.raymond=tomtom@python.org] On Behalf Of har...@moonshots.co.in Sent: Thursday, August 30, 2018 4:31 AM To: python-list@python.org Subject: Re: How to sort over dictionaries > > sort = sorted(results, key=lambda res:ite

Re: How to sort over dictionaries

2018-08-30 Thread harish
> > sort = sorted(results, key=lambda res:itemgetter('date')) > > print(sort) > > > > > > I have tried the above code peter but it was showing error like > > TypeError: '<' not supported between instances of 'operator.itemgetter' > > and 'operator.itemgetter' > > lambda res: itemgetter('

Re: How to sort over dictionaries

2018-08-29 Thread Peter Otten
har...@moonshots.co.in wrote: > sort = sorted(results, key=lambda res:itemgetter('date')) > print(sort) > > > I have tried the above code peter but it was showing error like > TypeError: '<' not supported between instances of 'operator.itemgetter' > and 'operator.itemgetter' lambda res: it

Re: How to sort over dictionaries

2018-08-29 Thread harish
> > > On Wednesday, August 29, 2018 at 11:20:26 AM UTC+5:30, John Ladasky wrote: > >> The top-level object you are showing is a list [], not a dictionary {}. > >> It has dictionaries inside of it though. Do you want to sort the list? > >> > >> Pyt

RE: How to sort over dictionaries

2018-08-29 Thread David Raymond
Well, that's a list of... somethings. So I'm assuming you mean sort a list of dictionaries? foo.sort(key = lambda x: time.strptime(x["date"], "%d-%m-%Y %H:%M")) with , reverse = True in the sort if you want it sorted in reverse -Original Message- Fro

How to sort over dictionaries

2018-08-29 Thread harish
[, https://getbootstrap.com/', 'author': 'Hari', 'date': '15-08-2018 15:15', 'headline': 'latest news'}>, , https://www.deps.co/blog/google-cloud-platform-good-bad-ugly/', 'author': 'Harish', 'headline': 'Google Cloud Platform – The Good, Bad, and Ugly', 'date': '16-08-2018 08:15'}>, , , http:

Re: How to sort over dictionaries

2018-08-29 Thread Peter Otten
har...@moonshots.co.in wrote: > On Wednesday, August 29, 2018 at 11:20:26 AM UTC+5:30, John Ladasky wrote: >> The top-level object you are showing is a list [], not a dictionary {}. >> It has dictionaries inside of it though. Do you want to sort the list? >> >>

Re: How to sort over dictionaries

2018-08-29 Thread harish
On Wednesday, August 29, 2018 at 11:20:26 AM UTC+5:30, John Ladasky wrote: > The top-level object you are showing is a list [], not a dictionary {}. It > has dictionaries inside of it though. Do you want to sort the list? > > Python's sorted() function returns a sorted c

Re: How to sort over dictionaries

2018-08-28 Thread John Ladasky
The top-level object you are showing is a list [], not a dictionary {}. It has dictionaries inside of it though. Do you want to sort the list? Python's sorted() function returns a sorted copy of a sequence. Sorted() has an optional argument called "key". Key accepts a second

Release of Scalpl (v0.2.5) ✨🍰✨ - a lightweight wrapper for your nested dictionaries

2017-06-26 Thread guillaume . paulet
Hi everyone ! I released a new version (0.2.5) of **Scalpl** which is available on PyPI :) https://github.com/ducdetronquito/scalpl You can install it via pip: pip3 install scalpl Scalpl is a lightweight wrapper that helps you to operate on nested dictionaries through the built-in dict

Re: Working with dictionaries and keys help please!

2017-06-02 Thread Gregory Ewing
On Thu, 1 Jun 2017 10:29 am, David D wrote: Is there a way of performing this where the key will update so that is continues to work sequentially? It sounds like you don't want a dictionary at all, you want a list. You can use the index() method to find the current "key" of an entry. >>> peop

Re: Working with dictionaries and keys help please!

2017-06-01 Thread Steve D'Aprano
On Thu, 1 Jun 2017 10:29 am, David D wrote: > I have a dictionary with a 10 people, the key being a number (0-10) and the > value being the people's name. I am in the processing of Insert, Adding and > deleting from the dictionary. All seems well until I delete a person and add > a new one. The

Re: Working with dictionaries and keys help please!

2017-05-31 Thread David D
Learning about dictionaries for a database possibly in the future. On Wednesday, May 31, 2017 at 8:58:39 PM UTC-4, MRAB wrote: > On 2017-06-01 01:29, David D wrote: > > I have a dictionary with a 10 people, the key being a number (0-10) and the > > value being the people'

Re: Working with dictionaries and keys help please!

2017-05-31 Thread MRAB
On 2017-06-01 01:29, David D wrote: I have a dictionary with a 10 people, the key being a number (0-10) and the value being the people's name. I am in the processing of Insert, Adding and deleting from the dictionary. All seems well until I delete a person and add a new one. The numbers (ke

Working with dictionaries and keys help please!

2017-05-31 Thread David D
I have a dictionary with a 10 people, the key being a number (0-10) and the value being the people's name. I am in the processing of Insert, Adding and deleting from the dictionary. All seems well until I delete a person and add a new one. The numbers (keys) do not change and so I am getting

[Ask for Review] Scalpl: A lightweight wrapper to operate on nested dictionaries (yet another)

2017-05-29 Thread guillaume . paulet
/ducdetronquito/scalpl It is a lightweight wrapper that helps you to operate on nested dictionaries through the built-in dict API, by using dot-separated string keys. You might find it useful when working with document-oriented database queries, REST APIs, configuration files, etc... It's

Re: Why this list of dictionaries doesn't work?

2015-06-18 Thread Steven D'Aprano
On Fri, 19 Jun 2015 03:57 am, Gilcan Machado wrote: > Hi, > > I'm trying to write a list of dictionaries like: > > people = ( > {'name':'john', 'age':12} , > {'name':'kacey', 'age':18}

Re: Why this list of dictionaries doesn't work?

2015-06-18 Thread Gary Herron
On 06/18/2015 10:57 AM, Gilcan Machado wrote: Hi, I'm trying to write a list of dictionaries like: people = ( {'name':'john', 'age':12} , {'name':'kacey', 'age':18} ) I've thought the code below wou

Re: Why this list of dictionaries doesn't work?

2015-06-18 Thread MRAB
On 2015-06-18 18:57, Gilcan Machado wrote: Hi, I'm trying to write a list of dictionaries like: people = ( {'name':'john', 'age':12} , {'name':'kacey', 'age':18} ) That's not a list; it's

Why this list of dictionaries doesn't work?

2015-06-18 Thread Gilcan Machado
Hi, I'm trying to write a list of dictionaries like: people = ( {'name':'john', 'age':12} , {'name':'kacey', 'age':18} ) I've thought the code below would do the task. But it doesn't work. And if

Re: Writing list of dictionaries to CSV [correction]

2015-05-06 Thread Tim Chase
On 2015-05-06 20:22, Tim Chase wrote: > As ChrisA posted earlier, you have to use Excel's Import > functionality (there are several ways to get this wizard, but not > all ways of opening a .csv trigger the wizard), then specify those > particular columns as "Text" rather than "General" Sorry, it w

Re: Writing list of dictionaries to CSV

2015-05-06 Thread Jon Ribbens
On 2015-05-06, Denis McMahon wrote: > You need to format your CSV date into a date format that Excel > understands when it imports it. > > First thing to try would be to export some dates from excel as CSV and > see what format excel puts them in. Beware of assuming that Excel can import its ow

Re: Writing list of dictionaries to CSV

2015-05-06 Thread Tim Chase
On 2015-05-06 23:31, Denis McMahon wrote: > On Tue, 05 May 2015 22:32:28 -0700, Kashif Rana wrote: > > thanks for the feedback. I think its problem with excel itself, > > showing wrong value. Because when I opened the csv file in text > > editor, I can see correct value but opening in excel showing

Re: Writing list of dictionaries to CSV

2015-05-06 Thread Denis McMahon
On Tue, 05 May 2015 22:32:28 -0700, Kashif Rana wrote: > thanks for the feedback. I think its problem with excel itself, showing > wrong value. Because when I opened the csv file in text editor, I can > see correct value but opening in excel showing wrong value. What I can > do to see correct in e

Re: Writing list of dictionaries to CSV

2015-05-06 Thread Tim Chase
On 2015-05-06 12:27, Ian Kelly wrote: > On Wed, May 6, 2015 at 12:22 PM, Tim Chase > wrote: > > On 2015-05-06 19:08, MRAB wrote: > >> You could tell it to quote any value that's not a number: > >> > >> w = csv.DictWriter(f, pol_keys, > >> quoting=csv.QUOTE_NONNUMERIC) > >> > >> It looks like

Re: Writing list of dictionaries to CSV

2015-05-06 Thread Ian Kelly
On Wed, May 6, 2015 at 12:22 PM, Tim Chase wrote: > On 2015-05-06 19:08, MRAB wrote: >> You could tell it to quote any value that's not a number: >> >> w = csv.DictWriter(f, pol_keys, >> quoting=csv.QUOTE_NONNUMERIC) >> >> It looks like all of the values you have are strings, so they'll >> a

Re: Writing list of dictionaries to CSV

2015-05-06 Thread Tim Chase
On 2015-05-06 19:08, MRAB wrote: > You could tell it to quote any value that's not a number: > > w = csv.DictWriter(f, pol_keys, > quoting=csv.QUOTE_NONNUMERIC) > > It looks like all of the values you have are strings, so they'll > all be quoted. > > I would hope that Excel will then treat

Re: Writing list of dictionaries to CSV

2015-05-06 Thread MRAB
t would be stupid if it didn't! :-) On Tuesday, May 5, 2015 at 9:09:40 PM UTC+4, Kashif Rana wrote: Hello Experts When I am writing list of dictionaries to CSV file, the key 'schedule' has value 'Mar 2012' becomes Mar-12. I really do not have clue why thats happening. B

Re: Writing list of dictionaries to CSV

2015-05-06 Thread Cecil Westerhof
Op Wednesday 6 May 2015 07:32 CEST schreef Kashif Rana: > thanks for the feedback. I think its problem with excel itself, > showing wrong value. Because when I opened the csv file in text > editor, I can see correct value but opening in excel showing wrong > value. What I can do to see correct in

Re: Writing list of dictionaries to CSV

2015-05-05 Thread Chris Angelico
On Wed, May 6, 2015 at 3:32 PM, Kashif Rana wrote: > thanks for the feedback. I think its problem with excel itself, showing wrong > value. Because when I opened the csv file in text editor, I can see correct > value but opening in excel showing wrong value. What I can do to see correct > in ex

Re: Writing list of dictionaries to CSV

2015-05-05 Thread Kashif Rana
at 9:09:40 PM UTC+4, Kashif Rana wrote: > Hello Experts > > When I am writing list of dictionaries to CSV file, the key 'schedule' has > value 'Mar 2012' becomes Mar-12. I really do not have clue why thats > happening. Below is the code. > > dic

Re: Writing list of dictionaries to CSV

2015-05-05 Thread Tim Chase
On 2015-05-05 10:09, Kashif Rana wrote: > When I am writing list of dictionaries to CSV file, the key > 'schedule' has value 'Mar 2012' becomes Mar-12. How are you making this determination? Are you looking at the raw CSV output, or are you looking at the CSV file load

Re: Writing list of dictionaries to CSV

2015-05-05 Thread Matthew Ruffalo
On 2015-05-05 14:25, Skip Montanaro wrote: > More likely, viewing the CSV file in Excel, Gnumeric, or some other > spreadsheet which interprets some inputs as dates and formats them > according to its default rules. Skip This is depressingly common, and I've even received CSV and plain text data

Re: Writing list of dictionaries to CSV

2015-05-05 Thread Cecil Westerhof
Op Tuesday 5 May 2015 19:09 CEST schreef Kashif Rana: > When I am writing list of dictionaries to CSV file, the key > 'schedule' has value 'Mar 2012' becomes Mar-12. I really do not have > clue why thats happening. Below is the code. > > dic_1 = {'action&#

Re: Writing list of dictionaries to CSV

2015-05-05 Thread Skip Montanaro
On Tue, May 5, 2015 at 1:11 PM, MRAB wrote: > I'm assuming that you're reading the CSV file in a text editor, not > some other application that might be trying to be "clever" by > "interpreting" what it thinks looks a date as a date and then > displaying it differently... More likely, viewing the

Re: Writing list of dictionaries to CSV

2015-05-05 Thread MRAB
On 2015-05-05 18:09, Kashif Rana wrote: Hello Experts When I am writing list of dictionaries to CSV file, the key 'schedule' has value 'Mar 2012' becomes Mar-12. I really do not have clue why thats happening. Below is the code. dic_1 = {'action': 'permit&#x

Writing list of dictionaries to CSV

2015-05-05 Thread Kashif Rana
Hello Experts When I am writing list of dictionaries to CSV file, the key 'schedule' has value 'Mar 2012' becomes Mar-12. I really do not have clue why thats happening. Below is the code. dic_1 = {'action': 'permit', 'dst-address': '

Re: Sort list of dictionaries

2015-03-03 Thread Peter Otten
Charles Heizer wrote: > On Monday, March 2, 2015 at 11:23:37 AM UTC-8, Peter Otten wrote: >> Charles Heizer wrote: >> >> > Never mind, the light bulb finally went off. :-\ >> > >> > sortedlist = sorted(mylist , key=lambda elem: "%s %s" % ( elem['name'], >> > (".".join([i.zfill(5) for i in elem['

Re: Sort list of dictionaries

2015-03-03 Thread Paul Moore
On Tuesday, 3 March 2015 16:09:31 UTC, Chris Angelico wrote: > On Wed, Mar 4, 2015 at 2:56 AM, Charles Heizer wrote: > >> Personally, I prefer to not use a lambda: > >> > >> def name_version(elem): > >> return elem['name'], LooseVersion(elem['version']) > >> > >> result = sorted(mylist, key=na

Re: Sort list of dictionaries

2015-03-03 Thread Chris Angelico
On Wed, Mar 4, 2015 at 2:56 AM, Charles Heizer wrote: >> Personally, I prefer to not use a lambda: >> >> def name_version(elem): >> return elem['name'], LooseVersion(elem['version']) >> >> result = sorted(mylist, key=name_version, reverse=True) > > Peter, thank you. Me being new to Python why

Re: Sort list of dictionaries

2015-03-03 Thread Charles Heizer
On Monday, March 2, 2015 at 11:23:37 AM UTC-8, Peter Otten wrote: > Charles Heizer wrote: > > > Never mind, the light bulb finally went off. :-\ > > > > sortedlist = sorted(mylist , key=lambda elem: "%s %s" % ( elem['name'], > > (".".join([i.zfill(5) for i in elem['version'].split(".")])) ), > >

Re: Sort list of dictionaries

2015-03-03 Thread Chris Angelico
On Wed, Mar 4, 2015 at 1:45 AM, Jason Friedman wrote: > I appreciate > how Python makes my job easier by doing much of my work for me. A > colleague yesterday asked how I guaranteed my temporary file names > would not collide with another file, and my answer was I don't have to > worry about it,

Re: Sort list of dictionaries

2015-03-03 Thread Jason Friedman
On Tue, Mar 3, 2015 at 12:07 AM, Chris Angelico wrote: > Heh, I think that mght be a bit abusive :) I'm not sure that > you want to depend on the version numbers fitting inside the rules for > IP addresses, especially given that the example has a component of > "2214". > Indeed, I was mi

Re: Sort list of dictionaries

2015-03-03 Thread Steven D'Aprano
Charles Heizer wrote: > Hello, > I'm new to python and I'm trying to find the right way to solve this issue > I have. > > I'm trying to sort this list by name and then by version numbers. The > problem I'm having is that I can not get the version numbers sorted with > the highest at the top or so

  1   2   3   4   5   6   7   8   9   10   >