Change the array declaration syntax.

(Sorry for any spelling errors, I'm using Google translator to write this message) Lists and tuples are data structures dynamically typed, and that's great! Makes writing code easier, and allows the developer to keep the focus on more important things. However, when these structures contain large amounts of elements, or when the program requires a lot of computational resources, dynamic typingbecomes a waste if the lists and tuples not use it. One way to avoid wasting resources with dynamic typing where it is unnecessary is to use the array class. The current syntax for creating arrays is:
This class is the solution when working with lists, but there is something similar when working with tuples. Thus, the variable "var" is a list, not a tuple, even if it is declared with with a tuple instead of a list:
I think, as well as raw strings in Python 2, lists and tuples could be declared a "single type" using a prefix.
My suggestion is to allow the type of element in the list or tuple is specified if the addition of a prefix before '[' or '('. This would simplify the use of arrays and improve the performance of programs that make use of lists of "single type". Besides creating tuples " single type". This seems more efficient, not wasting computing resources without polluting the code or make the language more complicated. For more information about the class array, the address of the documentation is http://docs.python.org/library/array.html . Thank You and Goodbye! Sig: Arthur Julião -------------------------------------------------- ---------------------------------------------- "Quero que a estrada venha sempre até você e que o vento esteja sempre a seu favor, quero que haja sempre uma cerveja em sua mão e que esteja ao seu lado seu grande amor." (Tempo Ruim - A Arte do Insulto - Matanza)

On Tue, Feb 8, 2011 at 12:52, Arthur <azrael.zila@gmail.com> wrote:
These statements are already meaningful: the first is a get-item of i with the key (1, 2, 3), the second is a function call of i with the arguments '1', '2' and '3'. This makes it unlikely the syntax will ever change this way. On the bright side, this means you can easily implement the shortcuts you want in today's Python, if you need them in a project. Cheers, Dirkjan

On Tue, Feb 8, 2011 at 9:52 PM, Arthur <azrael.zila@gmail.com> wrote:
Note that an array is its own beast - it just happens to use list notation in its repr, as the square brackets contrast better with the parentheses used for the function call syntax. Regardless, if you want a quick and easy way to create arrays of particular types, just define your own constructor function:
Cheers, Nick. -- Nick Coghlan | ncoghlan@gmail.com | Brisbane, Australia

I thought about how to do but did not analyze the feasibility, sorry about that. It could be after the symbol']'and ')'. So would:
Até mais! Ass.: Arthur Julião ------------------------------------------------------------------------------------------------ "Quero que a estrada venha sempre até você e que o vento esteja sempre a seu favor, quero que haja sempre uma cerveja em sua mão e que esteja ao seu lado seu grande amor." (Tempo Ruim - A Arte do Insulto - Matanza) 2011/2/8 Nick Coghlan <ncoghlan@gmail.com>

On 2011-02-08, at 12:52 , Arthur wrote:
>>> import array >>> a = array.array('i', [1,2,3]) >>> a array('i', [1, 2, 3])
Since 2.4, arrays can be initialized using any iterable. They're not "lists" or "tuples", they're arrays, a separate data type. You can provide an xrange as initializer if you wish to: >>> array.array('i', xrange(5)) array('i', [0, 1, 2, 3, 4]) or even provide no initializer at all: >>> array.array('i') array('i')

The only thing one can do with a tuple that cannot be done with a list is hash it for use as a dict key. And this is the only thing that would be gained with an immutable homogeneous array type. But tuple keys are typically so short (two or three items) that there is little need for anything else. Besides which, in 3.x, bytes are immutable sequences of (small) ints and are also available as dict keys. -- Terry Jan Reedy

On Tue, Feb 8, 2011 at 12:52, Arthur <azrael.zila@gmail.com> wrote:
These statements are already meaningful: the first is a get-item of i with the key (1, 2, 3), the second is a function call of i with the arguments '1', '2' and '3'. This makes it unlikely the syntax will ever change this way. On the bright side, this means you can easily implement the shortcuts you want in today's Python, if you need them in a project. Cheers, Dirkjan

On Tue, Feb 8, 2011 at 9:52 PM, Arthur <azrael.zila@gmail.com> wrote:
Note that an array is its own beast - it just happens to use list notation in its repr, as the square brackets contrast better with the parentheses used for the function call syntax. Regardless, if you want a quick and easy way to create arrays of particular types, just define your own constructor function:
Cheers, Nick. -- Nick Coghlan | ncoghlan@gmail.com | Brisbane, Australia

I thought about how to do but did not analyze the feasibility, sorry about that. It could be after the symbol']'and ')'. So would:
Até mais! Ass.: Arthur Julião ------------------------------------------------------------------------------------------------ "Quero que a estrada venha sempre até você e que o vento esteja sempre a seu favor, quero que haja sempre uma cerveja em sua mão e que esteja ao seu lado seu grande amor." (Tempo Ruim - A Arte do Insulto - Matanza) 2011/2/8 Nick Coghlan <ncoghlan@gmail.com>

On 2011-02-08, at 12:52 , Arthur wrote:
>>> import array >>> a = array.array('i', [1,2,3]) >>> a array('i', [1, 2, 3])
Since 2.4, arrays can be initialized using any iterable. They're not "lists" or "tuples", they're arrays, a separate data type. You can provide an xrange as initializer if you wish to: >>> array.array('i', xrange(5)) array('i', [0, 1, 2, 3, 4]) or even provide no initializer at all: >>> array.array('i') array('i')

The only thing one can do with a tuple that cannot be done with a list is hash it for use as a dict key. And this is the only thing that would be gained with an immutable homogeneous array type. But tuple keys are typically so short (two or three items) that there is little need for anything else. Besides which, in 3.x, bytes are immutable sequences of (small) ints and are also available as dict keys. -- Terry Jan Reedy
participants (5)
-
Arthur
-
Dirkjan Ochtman
-
Masklinn
-
Nick Coghlan
-
Terry Reedy