Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding an index method to tuples #44818

Closed
pboddie mannequin opened this issue Apr 8, 2007 · 8 comments
Closed

Adding an index method to tuples #44818

pboddie mannequin opened this issue Apr 8, 2007 · 8 comments
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-feature A feature request or enhancement

Comments

@pboddie
Copy link
Mannequin

pboddie mannequin commented Apr 8, 2007

BPO 1696444
Nosy @loewis, @rhettinger, @josiahcarlson
Files
  • tuple_index_26.diff: Patch adding tuple.index to the trunk
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2008-02-07.06:25:40.347>
    created_at = <Date 2007-04-08.14:35:47.000>
    labels = ['interpreter-core', 'type-feature']
    title = 'Adding an index method to tuples'
    updated_at = <Date 2008-02-07.06:25:40.309>
    user = 'https://bugs.python.org/pboddie'

    bugs.python.org fields:

    activity = <Date 2008-02-07.06:25:40.309>
    actor = 'rhettinger'
    assignee = 'none'
    closed = True
    closed_date = <Date 2008-02-07.06:25:40.347>
    closer = 'rhettinger'
    components = ['Interpreter Core']
    creation = <Date 2007-04-08.14:35:47.000>
    creator = 'pboddie'
    dependencies = []
    files = ['7929']
    hgrepos = []
    issue_num = 1696444
    keywords = ['patch']
    message_count = 8.0
    messages = ['52400', '52401', '52402', '52403', '52404', '52405', '52406', '62136']
    nosy_count = 4.0
    nosy_names = ['loewis', 'rhettinger', 'pboddie', 'josiahcarlson']
    pr_nums = []
    priority = 'normal'
    resolution = 'out of date'
    stage = None
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue1696444'
    versions = ['Python 2.6', 'Python 3.0']

    @pboddie
    Copy link
    Mannequin Author

    pboddie mannequin commented Apr 8, 2007

    This is just a simple copy and paste from the list implementation - not exactly the most elegant solution, but perhaps a demonstration that technical limitations aren't the reason why the tuple doesn't have an index method. I suppose a common sequence function library would be best if such a feature were eventually deemed compelling.

    @josiahcarlson
    Copy link
    Mannequin

    josiahcarlson mannequin commented Apr 9, 2007

    Adding an .index method to tuples suggests that a tuple is more or less an immutable list. This is not the case. Typically tuples are used to hold disparate pieces of information of different semantics and types, where as a list typically contains a list of a single type with identical meaning. For examples we merely need to look at the outputs of str.partition and str.split .

    Suggested close.

    @rhettinger
    Copy link
    Contributor

    FWIW, I am no longer satisfied with the pat answer that "tuples are not immutable lists" or the "lists for for homogenous data, tuples are for hetrogenous data".

    Whether tuples should grow index() and count() methods should depend solely on whether real use cases arise often enough to warrant the new methods being added.

    Another consideration is that this feature request and discussion comes up so often that it may be worthwhile just to give-in to conserve our limited resources of time and brain-power.

    @pboddie
    Copy link
    Mannequin Author

    pboddie mannequin commented Apr 9, 2007

    See here for a recent extension of the discussion:

    http://groups.google.com/group/comp.lang.python/browse_frm/thread/7e9327a896c242e7/

    For what it's worth, bypassing the dogma, methods like index and count on tuples are not exactly compelling in many situations (as I've pointed out before), but such issues should hardly derail the core development effort. If people consider such methods useful and if it diminishes perceived inelegance without method proliferation, just add them: people will be less frustrated and feel listened to; the language will become more regular.

    The only downside is any additional memory consumption. Objections related to what such methods mean, or what a tuple itself should be taken to mean, risk venturing into dogma and a consequent time-consuming discussion which takes 100 times the effort of just getting stuff done. Just look at the referenced thread (and the others of recent times) for example material.

    @josiahcarlson
    Copy link
    Mannequin

    josiahcarlson mannequin commented Apr 9, 2007

    I wouldn't be averse to adding utility functions to some module where it would make sense. Generally, I would say collections (it has a deque and default dictionary already), though there is already a proposed constructor called 'count' that returns the counts of all items in a sequence as a default dictionary (requiring that the items all be hashable).

    The reason I'm not against utility functions is because then they would be usable for 3rd party non-list, non-tuple sequences, or even usable in cases like 'a = array.array(...); i = index(a, value)'.

    @rhettinger
    Copy link
    Contributor

    Adding a utility function for this is silly. Don't ignore the obvious, simple solution. If a type *needs* a method, add it. If not, don't.

    Also, the collecitons module should be about collections, not a dumping ground for random utility functions.

    @loewis
    Copy link
    Mannequin

    loewis mannequin commented Apr 14, 2007

    This patch is not acceptable in its current form, because it does not include test suite and documentation changes.

    Furthermore, as the objective seems to be consistency across collections, I would say that the patch should either add both count and index, or none at all. Even with that added, the collections would still not behave consistently: strings have many more linear-search methods (.rindex, .find, .rfind).

    @birkenfeld birkenfeld added interpreter-core (Objects, Python, Grammar, and Parser dirs) type-feature A feature request or enhancement labels Sep 20, 2007
    @rhettinger
    Copy link
    Contributor

    Py2.6 and Py3.0 now how have tuple.index() and tuple.count().

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    interpreter-core (Objects, Python, Grammar, and Parser dirs) type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants