Re: Suggested feature: slice syntax within tuples (or even more generally)?

2013-02-25 Thread Andrew Robinson
On 02/14/2013 05:23 AM, Terry Reedy wrote: On 2/13/2013 2:00 PM, stephenw...@gmail.com wrote: Hello, Would it be feasible to modify the Python grammar to allow ':' to generate slice objects everywhere rather than just indexers and top-level tuples of indexers? Right now in Py

Re: Differences creating tuples and collections.namedtuples

2013-02-22 Thread Steven D'Aprano
On Tue, 19 Feb 2013 22:38:32 -0500, Terry Reedy wrote: > On 2/18/2013 7:18 PM, Steven D'Aprano wrote: >> Terry Reedy wrote: >> >>> On 2/18/2013 6:47 AM, John Reid wrote: >>> >>>> I was hoping namedtuples could be used as replacements for tuples &g

Re: Differences creating tuples and collections.namedtuples

2013-02-20 Thread Roy Smith
In article , Chris Angelico wrote: > On Wed, Feb 20, 2013 at 2:38 PM, Terry Reedy wrote: > > Liskov Substitution Principle (LSP): I met this over 15 years ago reading > > debates among OOP enthusiasts about whether Rectangle should be a subclass > > of Square or Square a subclass of Rectangle,

Re: Differences creating tuples and collections.namedtuples

2013-02-19 Thread Chris Angelico
On Wed, Feb 20, 2013 at 2:38 PM, Terry Reedy wrote: > Liskov Substitution Principle (LSP): I met this over 15 years ago reading > debates among OOP enthusiasts about whether Rectangle should be a subclass > of Square or Square a subclass of Rectangle, and similarly, whether Ostrich > can be a legi

Re: Differences creating tuples and collections.namedtuples

2013-02-19 Thread Terry Reedy
On 2/18/2013 7:18 PM, Steven D'Aprano wrote: Terry Reedy wrote: On 2/18/2013 6:47 AM, John Reid wrote: I was hoping namedtuples could be used as replacements for tuples in all instances. This is a mistake in the following two senses. First, tuple is a class with instances while named

Re: Differences creating tuples and collections.namedtuples

2013-02-19 Thread Steven D'Aprano
On Mon, 18 Feb 2013 23:48:46 -0800, raymond.hettinger wrote: [...] > If your starting point is an existing iterable such as s=['Guido', > 'BDFL', 1], you have a couple of choices: p=Person(*s) or > p=Person._make(s). The latter form was put it to help avoid unpacking > and repacking the argumen

Re: Differences creating tuples and collections.namedtuples

2013-02-19 Thread Steven D'Aprano
On Mon, 18 Feb 2013 23:48:46 -0800, raymond.hettinger wrote: [...] > If your starting point is an existing iterable such as s=['Guido', > 'BDFL', 1], you have a couple of choices: p=Person(*s) or > p=Person._make(s). The latter form was put it to help avoid unpacking > and repacking the argumen

Re: Differences creating tuples and collections.namedtuples

2013-02-19 Thread Steven D'Aprano
Pardon me for the double-post, if any, my news client appears to have eaten my first reply. On Mon, 18 Feb 2013 23:48:46 -0800, raymond.hettinger wrote: [...] > If your starting point is an existing iterable such as s=['Guido', > 'BDFL', 1], you have a couple of choices: p=Person(*s) or > p=Pe

Re: Differences creating tuples and collections.namedtuples

2013-02-19 Thread Steven D'Aprano
On Mon, 18 Feb 2013 23:48:46 -0800, raymond.hettinger wrote: [...] > If your starting point is an existing iterable such as s=['Guido', > 'BDFL', 1], you have a couple of choices: p=Person(*s) or > p=Person._make(s). The latter form was put it to help avoid unpacking > and repacking the argumen

Re: Differences creating tuples and collections.namedtuples

2013-02-19 Thread John Reid
On 19/02/13 01:47, alex23 wrote: > On Feb 18, 9:47 pm, John Reid wrote: >> See http://article.gmane.org/gmane.comp.python.ipython.user/10270 for more >> info. > > One quick workaround would be to use a tuple where required and then > coerce it back to Result when needed as such: > > def sleep

Re: Differences creating tuples and collections.namedtuples

2013-02-19 Thread John Reid
On 19/02/13 00:18, Steven D'Aprano wrote: > Terry Reedy wrote: > >> On 2/18/2013 6:47 AM, John Reid wrote: >> >>> I was hoping namedtuples could be used as replacements for tuples >> > in all instances. >> >> This is a mistake in the

Re: Differences creating tuples and collections.namedtuples

2013-02-19 Thread Gregory Ewing
Steven D'Aprano wrote: py> class MyDict(dict): ... @classmethod ... def fromkeys(cls, func): ... # Expects a callback function that gets called with no arguments ... # and returns two items, a list of keys and a default value. ... return super(MyDict, cls).fromkeys

Re: Differences creating tuples and collections.namedtuples

2013-02-18 Thread Gregory Ewing
Steven D'Aprano wrote: Terry Reedy wrote: In fact, one reason to subclass a class is to change the initialization api. That might be a reason that people give, but it's a bad reason from the perspective of interface contracts, duck-typing and the LSP. Only if you're going to pass the cla

Re: Differences creating tuples and collections.namedtuples

2013-02-18 Thread raymond . hettinger
rson = namedtuple('Person', ['name', 'rank', 'serial_number']) With the current signature, instances can be created like this: p = Person('Guido', 'BDFL', 1) If instead, the __new__ signature matched that of regular tuples, you wou

Re: Dictionaries with tuples or tuples of tuples

2013-02-18 Thread Mitya Sirenef
On 02/18/2013 10:14 PM, Dave Angel wrote: On 02/18/2013 09:54 PM, Mitya Sirenef wrote: >> On 02/18/2013 09:17 PM, Jon Reyes wrote: >>> Thanks Dave and Mitya for enlightening me about dictionaries. I'm >>> still confused about this though: >> > >> > " so that if two >> > key objects are equal, t

Re: Dictionaries with tuples or tuples of tuples

2013-02-18 Thread Dave Angel
On 02/18/2013 09:54 PM, Mitya Sirenef wrote: On 02/18/2013 09:17 PM, Jon Reyes wrote: Thanks Dave and Mitya for enlightening me about dictionaries. I'm still confused about this though: > > " so that if two > key objects are equal, they stay equal, and if they differ, they stay > different

Re: Differences creating tuples and collections.namedtuples

2013-02-18 Thread Steven D'Aprano
e the same >>> initialization api. >> >> No, it is not a mistake. It is a problem with namedtuples that they >> violate the expectation that they should have the same constructor >> signature as other tuples. After all, namedtuples *are* tuples, they >> should be cons

Re: Dictionaries with tuples or tuples of tuples

2013-02-18 Thread Mitya Sirenef
On 02/18/2013 09:17 PM, Jon Reyes wrote: Thanks Dave and Mitya for enlightening me about dictionaries. I'm still confused about this though: > > " so that if two > key objects are equal, they stay equal, and if they differ, they stay > different. " > > What does this mean? I won't be comparing

Re: Dictionaries with tuples or tuples of tuples

2013-02-18 Thread Jon Reyes
Oh, I see, thanks! I was thinking I'll study 2.7 and once I'm comfortable with Python as a language I'll move to 3. Heck, I don't even know how to create a simple main method. -- http://mail.python.org/mailman/listinfo/python-list

Re: Dictionaries with tuples or tuples of tuples

2013-02-18 Thread Mark Lawrence
On 19/02/2013 01:38, Jon Reyes wrote: Hi Mark. Well, doesn't iteritems() work the same? It's iteritems for Python 2, items for Python 3. -- Cheers. Mark Lawrence -- http://mail.python.org/mailman/listinfo/python-list

Re: Dictionaries with tuples or tuples of tuples

2013-02-18 Thread Jon Reyes
Thanks Dave and Mitya for enlightening me about dictionaries. I'm still confused about this though: " so that if two key objects are equal, they stay equal, and if they differ, they stay different. " What does this mean? I won't be comparing key objects with one another. Also, when I had two

Re: Dictionaries with tuples or tuples of tuples

2013-02-18 Thread Dave Angel
On 02/18/2013 08:38 PM, Jon Reyes wrote: Hi Mark. Well, doesn't iteritems() work the same? or am I missing something? By the way I'm sure I read the dictionaries part of Python but I'm unsure if it would take int's as a key for dictionaries. I've been weaned on Java where the keys of hashmaps

Re: Differences creating tuples and collections.namedtuples

2013-02-18 Thread alex23
On Feb 18, 9:47 pm, John Reid wrote: > See http://article.gmane.org/gmane.comp.python.ipython.user/10270 for more > info. One quick workaround would be to use a tuple where required and then coerce it back to Result when needed as such: def sleep(secs): import os, time, parallel_helper

Re: Dictionaries with tuples or tuples of tuples

2013-02-18 Thread Mitya Sirenef
On 02/18/2013 08:38 PM, Jon Reyes wrote: Hi Mark. Well, doesn't iteritems() work the same? or am I missing something? By the way I'm sure I read the dictionaries part of Python but I'm unsure if it would take int's as a key for dictionaries. I've been weaned on Java where the keys of hashmaps

Re: Differences creating tuples and collections.namedtuples

2013-02-18 Thread Oscar Benjamin
is a problem with namedtuples that they violate > the expectation that they should have the same constructor signature as > other tuples. After all, namedtuples *are* tuples, they should be > constructed the same way. But they aren't, so that violates a reasonable > expectation.

Re: Dictionaries with tuples or tuples of tuples

2013-02-18 Thread Jon Reyes
Hi Mark. Well, doesn't iteritems() work the same? or am I missing something? By the way I'm sure I read the dictionaries part of Python but I'm unsure if it would take int's as a key for dictionaries. I've been weaned on Java where the keys of hashmaps are always Strings. PS: Just checked, wow

Re: Dictionaries with tuples or tuples of tuples

2013-02-18 Thread Mark Lawrence
On 19/02/2013 00:52, Jon Reyes wrote: So I have a dictionary and the key is a number. The values are either a single tuple or a tuple of tuples. Is there a better way to go about accessing the values of the dictionary? All the tuples contain four elements. So say: col = {"1": (0,

Re: Dictionaries with tuples or tuples of tuples

2013-02-18 Thread Roy Smith
r (one of the colons should be a comma). > The values are either a > single tuple or a tuple of tuples. Is there a better way to go about > accessing the values of the dictionary? All the tuples contain four elements. I would make all the values the same shape, i.e. all lists of

Re: Dictionaries with tuples or tuples of tuples

2013-02-18 Thread Jon Reyes
Sorry if I didn't check the code before I posted it, I just mocked it up in Google's editor. That's what Mitya suggested too, yep, I guess I just need to make it uniform to get rid of the extra checking. Thanks man! -- http://mail.python.org/mailman/listinfo/python-list

Re: Differences creating tuples and collections.namedtuples

2013-02-18 Thread Roy Smith
Terry Reedy wrote: > Initializaing a namedtuple from an iterable is unusual, and > hence gets the longer syntax. I I quick look through our codebase agrees with that. I found 27 namedtuple classes. 21 were initialized with MyTuple(x, y, z) syntax. Three used MyTuple(*data). Most interesti

Re: Dictionaries with tuples or tuples of tuples

2013-02-18 Thread Jon Reyes
Wow, why didn't I think of that. Thanks! I'll try it now. By the way I think I don't need to wrap the single tuples in runtime because I'm declaring that dictionary anyway beforehand and I could just do it right there. I won't be adding elements to the tuple. -- http:

Re: Dictionaries with tuples or tuples of tuples

2013-02-18 Thread Mitya Sirenef
On 02/18/2013 07:52 PM, Jon Reyes wrote: So I have a dictionary and the key is a number. The values are either a single tuple or a tuple of tuples. Is there a better way to go about accessing the values of the dictionary? All the tuples contain four elements. > > So say: >

Dictionaries with tuples or tuples of tuples

2013-02-18 Thread Jon Reyes
So I have a dictionary and the key is a number. The values are either a single tuple or a tuple of tuples. Is there a better way to go about accessing the values of the dictionary? All the tuples contain four elements. So say: col = {"1": (0,1,2,3): "2": ((0,1,2,3),(2,3,4,

Re: Differences creating tuples and collections.namedtuples

2013-02-18 Thread Steven D'Aprano
Terry Reedy wrote: > On 2/18/2013 6:47 AM, John Reid wrote: > >> I was hoping namedtuples could be used as replacements for tuples > > in all instances. > > This is a mistake in the following two senses. First, tuple is a class > with instances while namedtu

Re: Differences creating tuples and collections.namedtuples

2013-02-18 Thread Terry Reedy
On 2/18/2013 6:47 AM, John Reid wrote: I was hoping namedtuples could be used as replacements for tuples > in all instances. This is a mistake in the following two senses. First, tuple is a class with instances while namedtuple is a class factory that produces classes. (One could think

Re: Differences creating tuples and collections.namedtuples

2013-02-18 Thread John Reid
On 18/02/13 14:53, Oscar Benjamin wrote: > On 18 February 2013 14:23, John Reid wrote: > [snip] >> That said it would be nice to know the rationale for >> namedtuple.__new__ to have a different signature to tuple.__new__. I'm >> guessing namedtuple._make has a similar interface to tuple.__new__. D

Re: Differences creating tuples and collections.namedtuples

2013-02-18 Thread Oscar Benjamin
On 18 February 2013 14:23, John Reid wrote: [snip] > That said it would be nice to know the rationale for > namedtuple.__new__ to have a different signature to tuple.__new__. I'm > guessing namedtuple._make has a similar interface to tuple.__new__. Does > anyone know what the rationale was for thi

Re: Differences creating tuples and collections.namedtuples

2013-02-18 Thread John Reid
On 18/02/13 14:15, Oscar Benjamin wrote: > On 18 February 2013 14:09, John Reid wrote: >> On 18/02/13 12:11, Dave Angel wrote: >>> On 02/18/2013 06:47 AM, John Reid wrote: >>>> Hi, >>>> >>>> I was hoping namedtuples could be used as replac

Re: Differences creating tuples and collections.namedtuples

2013-02-18 Thread Oscar Benjamin
On 18 February 2013 13:51, John Reid wrote: > On 18/02/13 12:03, Oscar Benjamin wrote: >> On 18 February 2013 11:47, John Reid wrote: >>> Hi, >>> >>> I was hoping namedtuples could be used as replacements for tuples in all >>> instances. >&g

Re: Differences creating tuples and collections.namedtuples

2013-02-18 Thread John Reid
On 18/02/13 14:12, Oscar Benjamin wrote: > On 18 February 2013 13:51, John Reid wrote: >> On 18/02/13 12:03, Oscar Benjamin wrote: >>> On 18 February 2013 11:47, John Reid wrote: >>>> Hi, >>>> >>>> I was hoping namedtuples could be

Re: Differences creating tuples and collections.namedtuples

2013-02-18 Thread Oscar Benjamin
On 18 February 2013 14:09, John Reid wrote: > On 18/02/13 12:11, Dave Angel wrote: >> On 02/18/2013 06:47 AM, John Reid wrote: >>> Hi, >>> >>> I was hoping namedtuples could be used as replacements for tuples in >>> all instances. There seem to b

Re: Differences creating tuples and collections.namedtuples

2013-02-18 Thread John Reid
On 18/02/13 12:11, Dave Angel wrote: > On 02/18/2013 06:47 AM, John Reid wrote: >> Hi, >> >> I was hoping namedtuples could be used as replacements for tuples in >> all instances. There seem to be some differences between how tuples >> and namedtuples are created.

Re: Differences creating tuples and collections.namedtuples

2013-02-18 Thread John Reid
On 18/02/13 12:03, Oscar Benjamin wrote: > On 18 February 2013 11:47, John Reid wrote: >> Hi, >> >> I was hoping namedtuples could be used as replacements for tuples in all >> instances. > namedtuples are not really intended to serves as tuples anywhere.

Re: Differences creating tuples and collections.namedtuples

2013-02-18 Thread John Reid
On 18/02/13 12:05, Oscar Benjamin wrote: > On 18 February 2013 12:03, Oscar Benjamin wrote: >> On 18 February 2013 11:47, John Reid wrote: >>> I'm seeing this problem because of the following code in IPython: >>> >>> def canSequence(obj): >>> if isinstance(obj, (list, tuple)): >>> t

Re: Differences creating tuples and collections.namedtuples

2013-02-18 Thread Dave Angel
On 02/18/2013 06:47 AM, John Reid wrote: Hi, I was hoping namedtuples could be used as replacements for tuples in all instances. There seem to be some differences between how tuples and namedtuples are created. For example with a tuple I can do: a=tuple([1,2,3]) with namedtuples I get a

Re: Differences creating tuples and collections.namedtuples

2013-02-18 Thread Oscar Benjamin
On 18 February 2013 12:03, Oscar Benjamin wrote: > On 18 February 2013 11:47, John Reid wrote: >> I'm seeing this problem because of the following code in IPython: >> >> def canSequence(obj): >> if isinstance(obj, (list, tuple)): >> t = type(obj) >> return t([can(i) for i in o

Re: Differences creating tuples and collections.namedtuples

2013-02-18 Thread Oscar Benjamin
On 18 February 2013 11:47, John Reid wrote: > Hi, > > I was hoping namedtuples could be used as replacements for tuples in all > instances. namedtuples are not really intended to serves as tuples anywhere. They are intended to provide lightweight, immutable, hashable objects

Differences creating tuples and collections.namedtuples

2013-02-18 Thread John Reid
Hi, I was hoping namedtuples could be used as replacements for tuples in all instances. There seem to be some differences between how tuples and namedtuples are created. For example with a tuple I can do: a=tuple([1,2,3]) with namedtuples I get a TypeError: from collections import namedtuple

Re: Suggested feature: slice syntax within tuples (or even more generally)?

2013-02-14 Thread Rick Johnson
On Thursday, February 14, 2013 4:01:39 PM UTC-6, steph...@gmail.com wrote: > On Thursday, February 14, 2013 1:58:06 PM UTC-5, Ian wrote: > > [snip: quote noise!] > Dude! Please trim this quote noise from your posts. I know Google's quoting mechanism is buggy, but dammit man YOU'RE A PROGRAMER!

Re: Suggested feature: slice syntax within tuples (or even more generally)?

2013-02-14 Thread stephenwlin
On Thursday, February 14, 2013 1:58:06 PM UTC-5, Ian wrote: > > That's not ambiguous, because the former is simply invalid syntax. > > However, consider the following. > > > > if 1: 2: > > > > That could be either a one-line if statement where the condition is 1 > > and the body is slice(2

Re: Suggested feature: slice syntax within tuples (or even more generally)?

2013-02-14 Thread Ian Kelly
On Thu, Feb 14, 2013 at 1:03 AM, Steven D'Aprano wrote: > E.g.: > > if x: > pass > > > Is that intended as "if slice(x, None, None)" with a missing colon, or > "if x" with colon supplied? That's not ambiguous, because the former is simply invalid syntax. However, consider the following. if 1

Re: Suggested feature: slice syntax within tuples (or even more generally)?

2013-02-14 Thread stephenwlin
> > You can't just allow ':' to generate slice objects everwhere without > > introducing ambiguity, so your proposal would have to be to allow slice > > objects in wider but still restricted contexts. Yeah, I mentioned that in a follow-up. I'm pretty sure of just allowing it within [] and ()

Re: Suggested feature: slice syntax within tuples (or even more generally)?

2013-02-14 Thread Duncan Booth
stephenw...@gmail.com wrote: > Would it be feasible to modify the Python grammar to allow ':' to > generate slice objects everywhere rather than just indexers and > top-level tuples of indexers? > Would this be a dict with a slice as key or value, or a set with a slice w

Re: Suggested feature: slice syntax within tuples (or even more generally)?

2013-02-14 Thread stephenwlin
> Hah, yes. I basically wrote that exact example in my reply to Steven at the > same time you replied. numpy.s_ is similar (although I think it does some > extra work for odd reasons). Oops, this is silly in retrospect...sorry, wasn't looking at the From: line carefully enough and didn't realiz

Re: Suggested feature: slice syntax within tuples (or even more generally)?

2013-02-14 Thread stephenwlin
On Thursday, February 14, 2013 3:03:50 AM UTC-5, Steven D'Aprano wrote: > On Wed, 13 Feb 2013 21:54:43 -0800, stephenwlin wrote: > > > > >> I believe the idea of slice literals has been rejected. > > >> > > >> > > > That's too bad...do you have a link to prior discussion on this and what >

Re: Suggested feature: slice syntax within tuples (or even more generally)?

2013-02-14 Thread stephenwlin
at all instead of requiring the user to build slice objects manually all the time? It obviously is a convenient and simpler syntax, and there doesn't seem to be any real reason for the artificial restriction that this happens inside '[]' (and in a shallow manner, so no nested

Re: Suggested feature: slice syntax within tuples (or even more generally)?

2013-02-14 Thread Steven D'Aprano
On Wed, 13 Feb 2013 21:54:43 -0800, stephenwlin wrote: >> I believe the idea of slice literals has been rejected. >> >> > That's too bad...do you have a link to prior discussion on this and what > the reasoning was for rejection? http://osdir.com/ml/python.python-3000.devel/2006-05/msg00686.ht

Re: Suggested feature: slice syntax within tuples (or even more generally)?

2013-02-13 Thread Steven D'Aprano
On Wed, 13 Feb 2013 21:54:43 -0800, stephenwlin wrote: >> I believe the idea of slice literals has been rejected. >> >> > That's too bad...do you have a link to prior discussion on this and what > the reasoning was for rejection? There doesn't seem to be any particular > downside and things wou

Re: Suggested feature: slice syntax within tuples (or even more generally)?

2013-02-13 Thread stephenwlin
dify the Python grammar to allow ':' to generate > slice objects everywhere rather than just indexers and top-level tuples of > indexers? > > > > Right now in Py2.7, Py3.3: > > "obj[:,2]" yields "obj[slice(None),2]" > > b

Re: Suggested feature: slice syntax within tuples (or even more generally)?

2013-02-13 Thread stephenwlin
> > I believe the idea of slice literals has been rejected. > That's too bad...do you have a link to prior discussion on this and what the reasoning was for rejection? There doesn't seem to be any particular downside and things would be more consistent with slice syntax allowed anywhere. It w

Re: Suggested feature: slice syntax within tuples (or even more generally)?

2013-02-13 Thread Terry Reedy
On 2/13/2013 2:00 PM, stephenw...@gmail.com wrote: Hello, Would it be feasible to modify the Python grammar to allow ':' to generate slice objects everywhere rather than just indexers and top-level tuples of indexers? Right now in Py2.7, Py3.3: "obj[:,2]" yields &quo

Suggested feature: slice syntax within tuples (or even more generally)?

2013-02-13 Thread stephenwlin
Hello, Would it be feasible to modify the Python grammar to allow ':' to generate slice objects everywhere rather than just indexers and top-level tuples of indexers? Right now in Py2.7, Py3.3: "obj[:,2]" yields "obj[slice(None),2]" but "obj[(:,

Re: Please provide a better explanation of tuples and dictionaries

2013-02-02 Thread Chris Angelico
On Sun, Feb 3, 2013 at 6:14 PM, Michael Torrie wrote: > TL;DR: I find your list freezing proposal to be needlessly complicated. > No the burden of proof is not on me to explain why tuples are so. We have a list-freezing mechanism already. >>> list=[1,2,3,'logical']

Re: Please provide a better explanation of tuples and dictionaries

2013-02-02 Thread Michael Torrie
is hardly foolish. In this case, as is usually the case with your strange criticisms of well-established practice, there are good reasons for it. TL;DR: I find your list freezing proposal to be needlessly complicated. No the burden of proof is not on me to explain why tuples are so. -- http:/

Re: Please provide a better explanation of tuples and dictionaries

2013-02-02 Thread Rick Johnson
?# The problem with understanding Python collections is directly due to improper naming. First let's consider the sequence types "list" and "tuple". For the most part lists and tuples are exactl

Re: Please provide a better explanation of tuples and dictionaries

2013-01-30 Thread rusi
ted learning Python (2.7.3) but need a better > explanation of how to use tuples and dictionaries. This is an important question: To start off you need to digest whats the diff between value oriented and object oriented. Since this is more to do with paradigm than with a specific language you may

Re: Please provide a better explanation of tuples and dictionaries

2013-01-29 Thread Steven D'Aprano
On Tue, 29 Jan 2013 22:14:42 -0800, Daniel W. Rouse Jr. wrote: > "John Gordon" wrote in message > news:keaa9v$1ru$1...@reader1.panix.com... >> A tuple is a linear sequence of items, accessed via subscripts that >> start at zero. >> >> Tuples are read-o

Re: Please provide a better explanation of tuples and dictionaries

2013-01-29 Thread Chris Angelico
, and changed in many ways; tuples are what they are, and there's no changing them (the objects inside it could be changed, but WHAT objects are in it won't). Python has no strict match to a C-style array with a fixed size and changeable members; a Python list is closest to a C++ std::v

Re: Please provide a better explanation of tuples and dictionaries

2013-01-29 Thread Daniel W. Rouse Jr.
"John Gordon" wrote in message news:keaa9v$1ru$1...@reader1.panix.com... In "Daniel W. Rouse Jr." writes: I have recently started learning Python (2.7.3) but need a better explanation of how to use tuples and dictionaries. A tuple is a linear sequence of items, acc

Re: Please provide a better explanation of tuples and dictionaries

2013-01-29 Thread John Gordon
In "Daniel W. Rouse Jr." writes: > I have recently started learning Python (2.7.3) but need a better > explanation of how to use tuples and dictionaries. A tuple is a linear sequence of items, accessed via subscripts that start at zero. Tuples are read-only; items cannot b

Re: Please provide a better explanation of tuples and dictionaries

2013-01-29 Thread Mitya Sirenef
On 01/29/2013 09:55 PM, Daniel W. Rouse Jr. wrote: Hi all, > > I have recently started learning Python (2.7.3) but need a better explanation of how to use tuples and dictionaries. > > I am currently using "Learning Python" by Mark Lutz and David Ascher, published by

Re: Please provide a better explanation of tuples and dictionaries

2013-01-29 Thread Chris Angelico
On Wed, Jan 30, 2013 at 2:42 PM, Daniel W. Rouse Jr. wrote: > "Chris Angelico" wrote in message > news:mailman.1197.1359515470.2939.python-l...@python.org... >> Have you checked out the online documentation at >> http://docs.python.org/ ? That might have what you're looking for. >> > I'll check t

Re: Please provide a better explanation of tuples and dictionaries

2013-01-29 Thread Daniel W. Rouse Jr.
92-464-9)--but I find the explanations insufficient and the number of examples to be sparse. I do understand some ANSI C programming in addition to Python (and the book often wanders off into a comparison of C and Python in its numerous footnotes), but I need a better real-world example of how tuples and di

Re: Please provide a better explanation of tuples and dictionaries

2013-01-29 Thread Chris Angelico
understand some > ANSI C programming in addition to Python (and the book often wanders off > into a comparison of C and Python in its numerous footnotes), but I need a > better real-world example of how tuples and dictionaries are being used in > actual Python code. Have you checked

Please provide a better explanation of tuples and dictionaries

2013-01-29 Thread Daniel W. Rouse Jr.
Hi all, I have recently started learning Python (2.7.3) but need a better explanation of how to use tuples and dictionaries. I am currently using "Learning Python" by Mark Lutz and David Ascher, published by O'Reilly (ISBN 1-56592-464-9)--but I find the explanations insuf

Re: Conversion of List of Tuples

2012-12-04 Thread Neil Cerutti
On 2012-12-04, Hans Mulder wrote: > It's considered bad style to use map it you don't want the list it > produces. > >> There are more ways: >> > from operator import add > reduce(add, a) >> (1, 2, 3, 4) > > There's a built-in that does "reduce(operator.add"; it's called "sum": > sum

Re: Conversion of List of Tuples

2012-12-04 Thread Hans Mulder
On 4/12/12 10:44:32, Alexander Blinne wrote: > Am 03.12.2012 20:58, schrieb subhabangal...@gmail.com: >> Dear Group, >> >> I have a tuple of list as, >> >> tup_list=[(1,2), (3,4)] >> Now if I want to covert as a simple list, >> >> list=[1,2,3,4] >> >> how may I do that? > > Another approach that h

Re: Conversion of List of Tuples

2012-12-04 Thread Alexander Blinne
Am 03.12.2012 20:58, schrieb subhabangal...@gmail.com: > Dear Group, > > I have a tuple of list as, > > tup_list=[(1,2), (3,4)] > Now if I want to covert as a simple list, > > list=[1,2,3,4] > > how may I do that? Another approach that has not yet been mentioned here: >>> a=[(1,2), (3,4)] >>>

Re: Conversion of List of Tuples

2012-12-04 Thread Gary Herron
On 12/03/2012 11:58 AM, subhabangal...@gmail.com wrote: [(1,2), (3,4)] >>> L=[(1,2), (3,4)] >>> >>> [b for a in L for b in a] [1, 2, 3, 4] -- Dr. Gary Herron Department of Computer Science DigiPen Institute of Technology (425) 895-4418 -- http://mail.python.org/mailman/listinfo/python-lis

Re: Conversion of List of Tuples

2012-12-03 Thread Walter Hurry
On Mon, 03 Dec 2012 22:11:40 +, Steven D'Aprano wrote: > On Mon, 03 Dec 2012 13:14:19 -0800, subhabangalore wrote: > >> Thanks. But I am not getting the counter "5posts 0 views"...if >> moderator can please check the issue. > > What counter are you talking about? > > This is an email mailin

Re: Conversion of List of Tuples

2012-12-03 Thread Steven D'Aprano
On Mon, 03 Dec 2012 13:14:19 -0800, subhabangalore wrote: > Thanks. But I am not getting the counter "5posts 0 views"...if moderator > can please check the issue. What counter are you talking about? This is an email mailing list, also copied to the Usenet newsgroup comp.lang.python, and mirrore

Re: Conversion of List of Tuples

2012-12-03 Thread John Gordon
In subhabangal...@gmail.com writes: > Thanks. But I am not getting the counter "5posts 0 views"...if > moderator can please check the issue. I logged in via Google Groups and all the replies were present. What is your question? (This group is not moderated.) -- John Gordon

Re: Conversion of List of Tuples

2012-12-03 Thread subhabangalore
On Tuesday, December 4, 2012 1:28:17 AM UTC+5:30, subhaba...@gmail.com wrote: > Dear Group, > > > > I have a tuple of list as, > > > > tup_list=[(1,2), (3,4)] > > Now if I want to covert as a simple list, > > > > list=[1,2,3,4] > > > > how may I do that? > > > > If any one can kindl

Re: Conversion of List of Tuples

2012-12-03 Thread Chris Angelico
On Tue, Dec 4, 2012 at 7:04 AM, John Gordon wrote: > In <6049bc85-6f8e-429b-a855-ecef47a9d...@googlegroups.com> > subhabangal...@gmail.com writes: > >> Dear Group, > >> I have a tuple of list as, > >> tup_list=[(1,2), (3,4)] >> Now if I want to covert as a simple list, > >> list=[1,2,3,4] > >> ho

Re: Conversion of List of Tuples

2012-12-03 Thread MRAB
On 2012-12-03 20:04, John Gordon wrote: In <6049bc85-6f8e-429b-a855-ecef47a9d...@googlegroups.com> subhabangal...@gmail.com writes: Dear Group, I have a tuple of list as, tup_list=[(1,2), (3,4)] Now if I want to covert as a simple list, list=[1,2,3,4] how may I do that? new_list

Re: Conversion of List of Tuples

2012-12-03 Thread Chris Kaynor
On Mon, Dec 3, 2012 at 11:58 AM, wrote: > Dear Group, > > I have a tuple of list as, > > tup_list=[(1,2), (3,4)] > Now if I want to covert as a simple list, > > list=[1,2,3,4] > > how may I do that? > > If any one can kindly suggest? Googling didn't help much. If you know they are always exactly

Re: Conversion of List of Tuples

2012-12-03 Thread John Gordon
In <6049bc85-6f8e-429b-a855-ecef47a9d...@googlegroups.com> subhabangal...@gmail.com writes: > Dear Group, > I have a tuple of list as, > tup_list=[(1,2), (3,4)] > Now if I want to covert as a simple list, > list=[1,2,3,4] > how may I do that? new_list = [] for t in tup_list: for item in

Conversion of List of Tuples

2012-12-03 Thread subhabangalore
Dear Group, I have a tuple of list as, tup_list=[(1,2), (3,4)] Now if I want to covert as a simple list, list=[1,2,3,4] how may I do that? If any one can kindly suggest? Googling didn't help much. Regards, Subhabrata. -- http://mail.python.org/mailman/listinfo/python-list

Re: Convert tuples into string

2012-11-25 Thread Tim Chase
On 11/25/12 20:24, Smaran Harihar wrote: > I was able to solve it using the following loop, > > conn=psycopg2.connect(connstr) > cursor=conn.cursor() > cursor.execute("SELECT tablename FROM pg_tables where tablename like '%"+ > inp +"%'") > records = cursor.fetchall() > str="" > for rec in record

Re: Convert tuples into string

2012-11-25 Thread Smaran Harihar
I was able to solve it using the following loop, conn=psycopg2.connect(connstr) cursor=conn.cursor() cursor.execute("SELECT tablename FROM pg_tables where tablename like '%"+ inp +"%'") records = cursor.fetchall() str="" for rec in records: if str == "": str="".join(rec) else: m="".join(rec) st

Re: Convert tuples into string

2012-11-25 Thread Cameron Simpson
On 25Nov2012 19:09, Smaran Harihar wrote: | I am connecting to postgres database and fetching the table names but it | seems that they are being returned in | | How can I convert them to string? Please show: - the code fetching the names; we do not know what library you are using or how

Convert tuples into string

2012-11-25 Thread Smaran Harihar
Hi Guys, I am connecting to postgres database and fetching the table names but it seems that they are being returned in How can I convert them to string? -- Thanks & Regards Smaran Harihar -- http://mail.python.org/mailman/listinfo/python-list

Re: A question of style (finding item in list of tuples)

2012-05-21 Thread Roy Smith
On Monday, May 21, 2012 9:39:59 AM UTC-4, Jon Clements wrote: > > def experience_text(self): > > return dict(CHOICES).get("self.level", "???") > Haven't used django in a while, but doesn't the model provide a > get_experience_display() method which you could use... Duh, I totally mi

Re: A question of style (finding item in list of tuples)

2012-05-21 Thread Jon Clements
of readability, which would you > find easier to understand when reading some new code? Assume the list > of choices is short enough that the cost of building a temporary dict on > each call is negligible. I'm just after style and readability here. Haven't used django in a

Re: A question of style (finding item in list of tuples)

2012-05-21 Thread Tim Chase
On 05/21/12 08:10, Steven D'Aprano wrote: > On Mon, 21 May 2012 08:37:29 -0400, Roy Smith wrote: > > [...] >> The above code works, but it occurs to me that I could use the much >> shorter: >> >> def experience_text(self): >> return dict(CHOICES).get("self.level", "???") >> >> So, the

Re: A question of style (finding item in list of tuples)

2012-05-21 Thread David Lambert
One suggestion is to construct the dictionary first: CHOICES = dict( NONE = 'No experience required', SAIL = 'Sailing experience, new to racing', RACE = 'General racing experience', GOOD = 'Experienced racer', ROCK = 'Rock star' ) def experience_text(self): try:

Re: A question of style (finding item in list of tuples)

2012-05-21 Thread Steven D'Aprano
On Mon, 21 May 2012 08:37:29 -0400, Roy Smith wrote: [...] > The above code works, but it occurs to me that I could use the much > shorter: > > def experience_text(self): > return dict(CHOICES).get("self.level", "???") > > So, the question is, purely as a matter of readability, which

Re: A question of style (finding item in list of tuples)

2012-05-21 Thread Chris Angelico
On Mon, May 21, 2012 at 10:37 PM, Roy Smith wrote: > The above code works, but it occurs to me that I could use the much > shorter: > >    def experience_text(self): >        return dict(CHOICES).get("self.level", "???") > > So, the question is, purely as a matter of readability, which would you >

A question of style (finding item in list of tuples)

2012-05-21 Thread Roy Smith
I've got this code in a django app: CHOICES = [ ('NONE', 'No experience required'), ('SAIL', 'Sailing experience, new to racing'), ('RACE', 'General racing experience'), ('GOOD', 'Experienced racer'), ('ROCK', 'Rock star'), ] def experience_

Re: Transform two tuples item by item

2011-12-19 Thread Gnarlodious
Wow, that is so elegant. Python is awesome. -- Gnarlie -- http://mail.python.org/mailman/listinfo/python-list

<    1   2   3   4   5   6   7   8   9   10   >