Re: [Python-ideas] get() method for list and tuples

2017-03-05 Thread Ethan Furman
On 03/05/2017 11:13 AM, Ed Kellett wrote: I'm not trying to get anyone to implement list.get, I'm trying to get it centrally > documented and allowed into list's overly-mappingproxied namespace. --> dir(list) # non dunder methods 'append', 'clear', 'copy', 'count', 'extend', 'index', 'insert',

Re: [Python-ideas] get() method for list and tuples

2017-03-05 Thread Paul Moore
On 5 March 2017 at 19:13, Ed Kellett wrote: >> I think we're going to have to just disagree. You won't convince me >> it's worth adding list.get unless you can demonstrate some *existing* >> costs that would be removed by adding list.get, and showing that they >> are greater than the costs of addi

Re: [Python-ideas] get() method for list and tuples

2017-03-05 Thread Mark Lawrence via Python-ideas
On 05/03/2017 20:16, Ed Kellett wrote: On Sun, 5 Mar 2017 at 19:54 David Mertz mailto:me...@gnosis.cx>> wrote: In terms of an actual use case, I can see it for "Lists no longer than 4". That's an excessively hard limit. Any other use of this hypothetical method would be an anti-pat

Re: [Python-ideas] get() method for list and tuples

2017-03-05 Thread David Mertz
On Sun, Mar 5, 2017 at 12:16 PM, Ed Kellett wrote: > On Sun, 5 Mar 2017 at 19:54 David Mertz wrote: > >> In terms of an actual use case, I can see it for "Lists no longer than 4". >> > Any other use of this hypothetical method would be an anti-pattern >> > > That's an excessively hard limit. >

Re: [Python-ideas] get() method for list and tuples

2017-03-05 Thread Ed Kellett
On Sun, 5 Mar 2017 at 19:54 David Mertz wrote: > In terms of an actual use case, I can see it for "Lists no longer than 4". > That's an excessively hard limit. > Any other use of this hypothetical method would be an anti-pattern > What really is the point of this? You (not uniquely) have been

Re: [Python-ideas] get() method for list and tuples

2017-03-05 Thread Chris Angelico
On Mon, Mar 6, 2017 at 6:13 AM, Ed Kellett wrote: > The point about this as a Python change is that it's a standard. Who does > the work couldn't be less relevant; what matters is that it would add a > consistent and easy spelling for something that doesn't have one. Oh, absolutely! Because a lan

Re: [Python-ideas] get() method for list and tuples

2017-03-05 Thread David Mertz
On Sun, Mar 5, 2017 at 11:22 AM, Ed Kellett wrote: > On Sun, 5 Mar 2017 at 18:13 David Mertz wrote: > >> data = args.get(17, "") >> >> Then I'm pretty sure the programmer thinks she's being passed a very >> different type of collection than is actually available. I'd rather that >> fails ri

Re: [Python-ideas] get() method for list and tuples

2017-03-05 Thread Ed Kellett
On Sun, 5 Mar 2017 at 18:13 David Mertz wrote: > But if the next line is: > > data = args.get(17, "") > > Then I'm pretty sure the programmer thinks she's being passed a very > different type of collection than is actually available. I'd rather that > fails right away and in an obvious way t

Re: [Python-ideas] get() method for list and tuples

2017-03-05 Thread Ed Kellett
On Sun, 5 Mar 2017 at 14:08 Paul Moore wrote: > Self-evidently no. But what does that prove? That we should implement > list.get? You could use the dientical argument for *anything*. There > needs to be another reason for implementing it. > I don't think that's true. It's not true for many other

Re: [Python-ideas] get() method for list and tuples

2017-03-05 Thread David Mertz
On Sun, Mar 5, 2017 at 10:13 AM, David Mertz wrote: > Specifically, if I think I'm dealing with a list that is likely to have 20 > items (rather than maybe 4 or fewer), I'm almost sure the best way to deal > with it is in a list (or comprehension, map(), etc) and NOT by poking into > large index

Re: [Python-ideas] get() method for list and tuples

2017-03-05 Thread David Mertz
On Sun, Mar 5, 2017 at 4:51 AM, Ed Kellett wrote: > It's hard to show examples because, generally speaking, when one can't do > a thing one does something else instead. I can restructure my programs to > avoid having this problem, or, if I'm in a hurry, I can use one of the many > ugly h^W^Wobvio

Re: [Python-ideas] get() method for list and tuples

2017-03-05 Thread Paul Moore
On 5 March 2017 at 13:03, Ed Kellett wrote: > > No. I'm asking: if list.get did exist, are there any cases (compatibility > with old versions aside) where list.get's semantics would be applicable, but > one of the alternatives would be the better choice? Self-evidently no. But what does that prov

Re: [Python-ideas] get() method for list and tuples

2017-03-05 Thread Ed Kellett
On Sun, 5 Mar 2017 at 11:27 Paul Moore wrote: > On 3 March 2017 at 18:29, Ed Kellett wrote: > > - Which of the existing things (slice + [default], conditional on a slice, > > conditional on a len() call) do you think is the obvious way to do it? > > Write a small wrapper function that implements

Re: [Python-ideas] get() method for list and tuples

2017-03-05 Thread Ed Kellett
On Sat, 4 Mar 2017 at 09:46 Steven D'Aprano wrote: On Fri, Mar 03, 2017 at 10:35:18PM +0100, Michel Desmoulin wrote: > Since the start of the discussion, contesters have been offering > numerous solutions, all being contextual and with gotchas, none being > obvious, simple or elegant. I do not

Re: [Python-ideas] get() method for list and tuples

2017-03-05 Thread Paul Moore
On 3 March 2017 at 18:29, Ed Kellett wrote: > I guess I don't have any hope of convincing people who think there's no need > to ever do this, but I have a couple of questions for the people who think > the existing solutions are fine: > > - Which of the existing things (slice + [default], conditio

Re: [Python-ideas] get() method for list and tuples

2017-03-04 Thread Steven D'Aprano
On Fri, Mar 03, 2017 at 10:35:18PM +0100, Michel Desmoulin wrote: > Since the start of the discussion, contesters have been offering > numerous solutions, all being contextual and with gotchas, none being > obvious, simple or elegant. I do not agree with that characterisation. > The best is sti

Re: [Python-ideas] get() method for list and tuples

2017-03-03 Thread Markus Meskanen
Hi, I'm still new here, but if my vote has any value then this gets a heavy -1 from me. It makes no sense to have to access exact i:th element of a list without knowing if it exists, at least not in a scenario where checking against the length or using an exception (say CSV row should have index 2

Re: [Python-ideas] get() method for list and tuples

2017-03-03 Thread Chris Barker
On Fri, Mar 3, 2017 at 1:35 PM, Michel Desmoulin wrote: > I am serious. It depends on the use case. If the data are an But that's the all problem isn't it? Since the start of the discussion, contesters have been offering numerous solutions, all being contextual and with gotchas, none being obvi

Re: [Python-ideas] get() method for list and tuples

2017-03-03 Thread Matt Gilson
On Fri, Mar 3, 2017 at 1:35 PM, Michel Desmoulin wrote: > > > Le 03/03/2017 à 22:21, Chris Barker a écrit : > > On Fri, Mar 3, 2017 at 12:21 PM, Sven R. Kunze > > wrote: > > > >> For my part, I think casting a list to a dict is often the RIGHT > >> way to address

Re: [Python-ideas] get() method for list and tuples

2017-03-03 Thread Ethan Furman
On 03/03/2017 01:35 PM, Michel Desmoulin wrote: The proposal is actionable, the cost of it seems low, and it's not remotely controversial. Several people are against this idea, several of them are core-devs, and you claim it's not *remotely* controversial? Really?? -- ~Ethan~ __

Re: [Python-ideas] get() method for list and tuples

2017-03-03 Thread Michel Desmoulin
Le 03/03/2017 à 22:21, Chris Barker a écrit : > On Fri, Mar 3, 2017 at 12:21 PM, Sven R. Kunze > wrote: > >> For my part, I think casting a list to a dict is often the RIGHT >> way to address these issues. > > You can't be serious about this. Especially beca

Re: [Python-ideas] get() method for list and tuples

2017-03-03 Thread Chris Barker
On Fri, Mar 3, 2017 at 12:33 PM, Sven R. Kunze wrote: > Right now, I could not think of an example "non-trivial and simple and > small enough" especially in the context of JSON. But maybe the other > proponents have. > Always a challenge -- sorry to lack imagination, I tend to need concrete exam

Re: [Python-ideas] get() method for list and tuples

2017-03-03 Thread Chris Barker
On Fri, Mar 3, 2017 at 12:21 PM, Sven R. Kunze wrote: > For my part, I think casting a list to a dict is often the RIGHT way to > address these issues. > > > You can't be serious about this. Especially because it would negate your > response to Ed "conditional on a len() call is the way to go". N

Re: [Python-ideas] get() method for list and tuples

2017-03-03 Thread Sven R. Kunze
Thanks Chris for your idea. Right now, I could not think of an example "non-trivial and simple and small enough" especially in the context of JSON. But maybe the other proponents have. The part of data series from simulations (so proper datastructures available). So, data lists which aren't

Re: [Python-ideas] get() method for list and tuples

2017-03-03 Thread Sven R. Kunze
On 03.03.2017 21:09, Chris Barker wrote: On Fri, Mar 3, 2017 at 12:02 PM, Sven R. Kunze > wrote: For me to think (list/tuple).get() was needed would be if lots of folk either cast their lists to dicts or made their own list-dict class to solve that problem.

Re: [Python-ideas] get() method for list and tuples

2017-03-03 Thread Chris Barker
On Fri, Mar 3, 2017 at 12:06 PM, Chris Barker wrote: > M.A. Lemberg has been talking about that on this list (in this thread? > I've lost track...) > it was in the "Optional parameters without default value" thread. -CHB -- Christopher Barker, Ph.D. Oceanographer Emergency Response Divisi

Re: [Python-ideas] get() method for list and tuples

2017-03-03 Thread Chris Barker
About JSON and schema-less data: I need to deal with this fairly often as well, but: JSON has a data model that includes both mappings and sequences: Sequences (arrays, lists, etc) are the "right" thing to use when an object has zero or more of something. Usually, these somethings are all the sa

Re: [Python-ideas] get() method for list and tuples

2017-03-03 Thread Chris Barker
On Fri, Mar 3, 2017 at 12:02 PM, Sven R. Kunze wrote: > For me to think (list/tuple).get() was needed would be if lots of folk > either cast their lists to dicts or made their own list-dict class to solve > that problem. > > > The easier solution would be to provide list.get ;-) > Exactly -- I t

Re: [Python-ideas] get() method for list and tuples

2017-03-03 Thread Chris Barker
On Fri, Mar 3, 2017 at 11:15 AM, Kyle Lahnakoski wrote: > Python > has a fundamentally different philosophy about None that conflicts with > what I need for my domain [2] where I am transforming and interpreting > data. Using a set of classes that make a different set of assumptions > about None

Re: [Python-ideas] get() method for list and tuples

2017-03-03 Thread Chris Barker
On Fri, Mar 3, 2017 at 11:01 AM, Sven R. Kunze wrote: > I wonder if those arguing against it also think dicts should not have item > access: > > a[0] > > dict or list? Why should it matter? > Because a mapping that happens to have an integer key is a fundamentally different thing than a sequence

Re: [Python-ideas] get() method for list and tuples

2017-03-03 Thread Sven R. Kunze
On 03.03.2017 20:35, Ethan Furman wrote: On 03/03/2017 11:01 AM, Sven R. Kunze wrote: On 03.03.2017 19:29, Ed Kellett wrote: The reasons already stated boil down to "lists aren't dicts so they shouldn't share methods", which seems ill-advised at best, and "I wouldn't use this". I wonder if

Re: [Python-ideas] get() method for list and tuples

2017-03-03 Thread Ethan Furman
On 03/03/2017 10:29 AM, Ed Kellett wrote: - Which of the existing things (slice + [default], conditional on a slice, conditional on a len() call) do you think is the obvious way to do it? [my_value] = some_list[offset:offset+1] or [default_value] -- ~Ethan~ __

Re: [Python-ideas] get() method for list and tuples

2017-03-03 Thread Ethan Furman
On 03/03/2017 11:01 AM, Sven R. Kunze wrote: On 03.03.2017 19:29, Ed Kellett wrote: The reasons already stated boil down to "lists aren't dicts so they shouldn't share methods", which seems ill-advised at best, and "I wouldn't use this". I wonder if those arguing against it also think dicts

Re: [Python-ideas] get() method for list and tuples

2017-03-03 Thread Kyle Lahnakoski
I must mention a get() method for lists and tuples would be very useful for me too. It is so useful, that I spent too much time making my own module to handle this case, plus many of the other dealing-with-None subjects found on this list. Michel is correct to point out that this is domain specif

Re: [Python-ideas] get() method for list and tuples

2017-03-03 Thread Ethan Furman
On 03/03/2017 10:48 AM, Sven R. Kunze wrote: On 03.03.2017 18:06, Ethan Furman wrote: On 03/02/2017 12:36 PM, Sven R. Kunze wrote: It then would make sense to remove .get() on dicts. ;-) and to remove parameter "default" of max(). and to remove parameter "default" of getattr(). Backwards

Re: [Python-ideas] get() method for list and tuples

2017-03-03 Thread Sven R. Kunze
On 03.03.2017 19:29, Ed Kellett wrote: The reasons already stated boil down to "lists aren't dicts so they shouldn't share methods", which seems ill-advised at best, and "I wouldn't use this". I wonder if those arguing against it also think dicts should not have item access: a[0] dict or l

Re: [Python-ideas] get() method for list and tuples

2017-03-03 Thread Sven R. Kunze
On 03.03.2017 18:06, Ethan Furman wrote: On 03/02/2017 12:36 PM, Sven R. Kunze wrote: On 01.03.2017 06:34, Ethan Furman wrote: On the bright side, if enough use-cases of this type come up (pesky try/except for a simple situation), we may be able to get Guido to reconsider PEP 463. I certainl

Re: [Python-ideas] get() method for list and tuples

2017-03-03 Thread Chris Angelico
On Sat, Mar 4, 2017 at 5:29 AM, Ed Kellett wrote: > I've often looked for something like a list.get, been frustrated, and used > one (chosen pretty much at random) of the ugly hacks presented in this > thread. I'd be surprised if I'm the only one. Can you show us some real-world code that would b

Re: [Python-ideas] get() method for list and tuples

2017-03-03 Thread Ed Kellett
On Fri, 3 Mar 2017 at 17:03 Ethan Furman wrote: > On 03/03/2017 08:09 AM, Ed Kellett wrote: > > > P.S. all the talk of PEP 463 seems misplaced. That it solves (FSVO > solve) this problem doesn't mean it should supersede > > this discussion. > > The advantage of PEP 463 is that issues like this wo

Re: [Python-ideas] get() method for list and tuples

2017-03-03 Thread Ethan Furman
On 03/02/2017 12:36 PM, Sven R. Kunze wrote: On 01.03.2017 06:34, Ethan Furman wrote: On the bright side, if enough use-cases of this type come up (pesky try/except for a simple situation), we may be able to get Guido to reconsider PEP 463. I certainly think PEP 463 makes a lot more sense t

Re: [Python-ideas] get() method for list and tuples

2017-03-03 Thread Ethan Furman
On 03/03/2017 08:09 AM, Ed Kellett wrote: P.S. all the talk of PEP 463 seems misplaced. That it solves (FSVO solve) this problem doesn't mean it should supersede this discussion. The advantage of PEP 463 is that issues like this would be less pressing, and it's much more general purpose. Pe

Re: [Python-ideas] get() method for list and tuples

2017-03-03 Thread Ed Kellett
On Tue, 28 Feb 2017 at 17:19 David Mertz wrote: > On Tue, Feb 28, 2017 at 7:16 AM, Michel Desmoulin < > desmoulinmic...@gmail.com> wrote: > > Le 28/02/2017 à 15:45, Steven D'Aprano a écrit : > > No you don't. You can use slicing. > > alist = [1, 2, 3] > > print(alist[99:100]) # get the item at p

Re: [Python-ideas] get() method for list and tuples

2017-03-03 Thread Sven R. Kunze
On 01.03.2017 06:34, Ethan Furman wrote: On the bright side, if enough use-cases of this type come up (pesky try/except for a simple situation), we may be able to get Guido to reconsider PEP 463. I certainly think PEP 463 makes a lot more sense that adding list.get(). It then would make sens

Re: [Python-ideas] get() method for list and tuples

2017-03-03 Thread Sven R. Kunze
On 02.03.2017 04:41, Chris Barker wrote: Maybe someone else will chime in with more "I'd really have a use for this" examples. It also makes refactoring easier. Regards, Sven ___ Python-ideas mailing list Python-ideas@python.org https://mail.python.

Re: [Python-ideas] get() method for list and tuples

2017-03-02 Thread Steven D'Aprano
On Wed, Mar 01, 2017 at 02:56:44AM +0100, Michel Desmoulin wrote: > > first_item = (alist[0:1] or ["ham"])[0] > > Come on, I've been doing Python for more than a decade and never saw > anybody doing that. Even reading it in a code would make me scratch my > head for a moment with a "what is it do

Re: [Python-ideas] get() method for list and tuples

2017-03-01 Thread Nick Coghlan
On 2 March 2017 at 07:03, David Mertz wrote: > On Wed, Mar 1, 2017 at 11:13 AM, Abe Dillon wrote: > >> I'd like to +1 this proposal. It should be trivial to implement. It won't >> break backward compatibility. It's intuitive. I can think of several places >> I would use it. I can't think of a go

Re: [Python-ideas] get() method for list and tuples

2017-03-01 Thread Chris Barker
On Tue, Feb 28, 2017 at 5:56 PM, Michel Desmoulin wrote: > Me, I have to deal SOAP government systems, mongodb based API built by > teenagers, geographer data set exports and FTP + CSV in marina systems > (which I happen to work on right now). > > 3rd party CSV, XML and JSON processing are just

Re: [Python-ideas] get() method for list and tuples

2017-03-01 Thread Chris Barker
On Tue, Feb 28, 2017 at 5:26 PM, Michel Desmoulin wrote: > Duck typing is precesily about incomplete but good enough similar API. > yes, though ideally one API is a subset of the other -- if they have the same method, it should mean the same thing: > For the dict and list: > > - you can itera

Re: [Python-ideas] get() method for list and tuples

2017-03-01 Thread Barry
> On 1 Mar 2017, at 19:13, Abe Dillon wrote: > > Barry, you're taking the metaphor too far. Duct typing is about presenting a > certain interface. If your function takes an object that has a get(key, > default) method, the rest doesn't matter. That's the only way in which the > object needs t

Re: [Python-ideas] get() method for list and tuples

2017-03-01 Thread David Mertz
On Wed, Mar 1, 2017 at 11:13 AM, Abe Dillon wrote: > I'd like to +1 this proposal. It should be trivial to implement. It won't > break backward compatibility. It's intuitive. I can think of several places > I would use it. I can't think of a good reason not to include it. > I've yet to see in th

Re: [Python-ideas] get() method for list and tuples

2017-03-01 Thread Abe Dillon
Barry, you're taking the metaphor too far. Duct typing is about presenting a certain interface. If your function takes an object that has a get(key, default) method, the rest doesn't matter. That's the only way in which the object needs to resemble a duck in your function. I'd like to +1 this prop

Re: [Python-ideas] get() method for list and tuples

2017-03-01 Thread Barry
> On 1 Mar 2017, at 01:26, Michel Desmoulin wrote: > > - you can iterate on both Maybe, bit do you want the keys, values or (key, value) items? Keys being the deafult. > - you can index both Maybe as you cannot in the general case know the index. Need keys(). > - you can size both Yes I think

Re: [Python-ideas] get() method for list and tuples

2017-02-28 Thread Ethan Furman
On 02/28/2017 06:02 PM, Michel Desmoulin wrote: Le 01/03/2017 à 02:23, Ethan Furman a écrit : On 02/28/2017 05:18 PM, Michel Desmoulin wrote: I love this proposal but Guido rejected it. Fighting for it right now would probably be detrimental to the current proposed feature which could potenti

Re: [Python-ideas] get() method for list and tuples

2017-02-28 Thread Steven D'Aprano
On Wed, Mar 01, 2017 at 02:26:18AM +0100, Michel Desmoulin wrote: > The fact the API is not exactly the same doesn't prevent duck typing. > Duck typing is precesily about incomplete but good enough similar API. Indeed. But the relationship goes this way: # Duck-typing done the right way.

Re: [Python-ideas] get() method for list and tuples

2017-02-28 Thread Chris Angelico
On Wed, Mar 1, 2017 at 1:02 PM, Michel Desmoulin wrote: > Le 01/03/2017 à 02:23, Ethan Furman a écrit : >> On 02/28/2017 05:18 PM, Michel Desmoulin wrote: >> >>> I love this proposal but Guido rejected it. Fighting for it right now >>> would probably be detrimental to the current proposed feature

Re: [Python-ideas] get() method for list and tuples

2017-02-28 Thread Michel Desmoulin
Le 01/03/2017 à 02:23, Ethan Furman a écrit : > On 02/28/2017 05:18 PM, Michel Desmoulin wrote: > >> I love this proposal but Guido rejected it. Fighting for it right now >> would probably be detrimental to the current proposed feature which >> could potentially be more easily accepted. > > PEP

Re: [Python-ideas] get() method for list and tuples

2017-02-28 Thread Michel Desmoulin
> > I am aware of that. I'm just saying you don't have to use try...except, > you can use slicing instead. Obviously you have to adapt the code since > you are getting a list not a single item: > > # may fail, if alist is empty > if alist[0] == "spam": ... > > # cannot fail > if alist[0:1] ==

Re: [Python-ideas] get() method for list and tuples

2017-02-28 Thread Michel Desmoulin
Le 01/03/2017 à 01:02, Steven D'Aprano a écrit : > On Tue, Feb 28, 2017 at 07:10:15PM +0100, Sven R. Kunze wrote: > >> 1. advantage: it looks like dict access -> allows duck typing (oh how >> often I'd missed that) > > Dicts and lists don't duck-type because they are very different things. >

Re: [Python-ideas] get() method for list and tuples

2017-02-28 Thread Ethan Furman
On 02/28/2017 05:18 PM, Michel Desmoulin wrote: I love this proposal but Guido rejected it. Fighting for it right now would probably be detrimental to the current proposed feature which could potentially be more easily accepted. PEP 463 has a better chance of being accepted than this one does,

Re: [Python-ideas] get() method for list and tuples

2017-02-28 Thread Michel Desmoulin
I love this proposal but Guido rejected it. Fighting for it right now would probably be detrimental to the current proposed feature which could potentially be more easily accepted. At least let's make it a separate thread. I would love to restart the debate about this one. This is one of my most w

Re: [Python-ideas] get() method for list and tuples

2017-02-28 Thread Rob Cliffe
On 28/02/2017 11:54, Michel Desmoulin wrote: dict.get() is a very useful method, but for lists and tuples, we need to rely on try/except instead. Can we get list.get and tuple.get as well? If PEP 463 "Exception-catching expressions" were accepted and implemented, we wouldn't need any of them:

Re: [Python-ideas] get() method for list and tuples

2017-02-28 Thread Steven D'Aprano
On Tue, Feb 28, 2017 at 07:10:15PM +0100, Sven R. Kunze wrote: > 1. advantage: it looks like dict access -> allows duck typing (oh how > often I'd missed that) Dicts and lists don't duck-type because they are very different things. We know what ["item"]*10 does. What would {"key": "value"}*10 d

Re: [Python-ideas] get() method for list and tuples

2017-02-28 Thread Steven D'Aprano
On Tue, Feb 28, 2017 at 04:16:28PM +0100, Michel Desmoulin wrote: > > > Le 28/02/2017 à 15:45, Steven D'Aprano a écrit : > > On Tue, Feb 28, 2017 at 12:54:26PM +0100, Michel Desmoulin wrote: > >> dict.get() is a very useful method, but for lists and tuples, we need to > >> rely on try/except inst

Re: [Python-ideas] get() method for list and tuples

2017-02-28 Thread Nick Timkovich
I wouldn't see myself using it for an arbitrary value in the middle of the list, but perhaps for the 0th or -1st (first/last) element of a list that might be empty. Maybe also second-to-first/last if I'm initializing some comparison between sequential items? Some of the examples don't work with ne

Re: [Python-ideas] get() method for list and tuples

2017-02-28 Thread David Mertz
On Tue, Feb 28, 2017 at 10:10 AM, Sven R. Kunze wrote: > Yes, and easily written as above. What significant advantage would it > have to spell the above as: > > x = alist.get(pos, default_val) > > It's a couple characters shorter in the proposed version. I guess I'll > concede that needing

Re: [Python-ideas] get() method for list and tuples

2017-02-28 Thread Sven R. Kunze
On 28.02.2017 18:18, David Mertz wrote: Yes, and easily written as above. What significant advantage would it have to spell the above as: x = alist.get(pos, default_val) It's a couple characters shorter in the proposed version. I guess I'll concede that needing the odd indexing at the

Re: [Python-ideas] get() method for list and tuples

2017-02-28 Thread David Mertz
On Tue, Feb 28, 2017 at 7:16 AM, Michel Desmoulin wrote: > Le 28/02/2017 à 15:45, Steven D'Aprano a écrit : > > No you don't. You can use slicing. > > alist = [1, 2, 3] > > print(alist[99:100]) # get the item at position 99 > > No this gives you a list of one item or an empty list. > > dict.get(

Re: [Python-ideas] get() method for list and tuples

2017-02-28 Thread Michel Desmoulin
Le 28/02/2017 à 15:45, Steven D'Aprano a écrit : > On Tue, Feb 28, 2017 at 12:54:26PM +0100, Michel Desmoulin wrote: >> dict.get() is a very useful method, but for lists and tuples, we need to >> rely on try/except instead. > > No you don't. You can use slicing. > > alist = [1, 2, 3] > print(al

Re: [Python-ideas] get() method for list and tuples

2017-02-28 Thread Steven D'Aprano
On Tue, Feb 28, 2017 at 12:54:26PM +0100, Michel Desmoulin wrote: > dict.get() is a very useful method, but for lists and tuples, we need to > rely on try/except instead. No you don't. You can use slicing. alist = [1, 2, 3] print(alist[99:100]) # get the item at position 99 In my experience, di

[Python-ideas] get() method for list and tuples

2017-02-28 Thread Michel Desmoulin
dict.get() is a very useful method, but for lists and tuples, we need to rely on try/except instead. Can we get list.get and tuple.get as well? Also, for list, a list.setdefault like the dict.setdefault would be logical. ___ Python-ideas mailing list Py