Opened 7 years ago

Closed 6 years ago

#1195 closed enhancement (wontfix)

The "len" function for lists and sequences

Reported by: ljpk Owned by: cwitty
Priority: minor Milestone: sage-2.10.3
Component: misc Keywords:
Cc: Merged in:
Authors: Reviewers:
Report Upstream: Work issues:
Branch: Commit:
Dependencies: Stopgaps:

Description (last modified by mabshoff)

Currently, the method to obtain the length of a list or sequence is:

my_list=Sequence([1,2,3,4])
len(my_list)

This is not consistent with either MAGMA or PARI, and there is no method attached to the sequence or list which gives the length.

I would like to suggest that a method be added so that

my_list.length()

would give the answer 4.

Change History (6)

comment:1 Changed 7 years ago by mabshoff

  • Description modified (diff)
  • Milestone set to sage-2.9

comment:2 Changed 7 years ago by mabshoff

  • Description modified (diff)

comment:3 Changed 7 years ago by mhansen

On the other hand, len() is the standard Python way of doing things.

comment:4 Changed 7 years ago by ncalexan

This is not quite true -- there is a .__len__() function that len() calls.

Perhaps this should be at the level of SageObject: .length() calls .__len__()? This is irritating but not idiomatic python, so I vote to keep it as is.

comment:5 Changed 6 years ago by malb

I vote against the proposal in this ticket, len(Foo) is the Python way.

comment:6 Changed 6 years ago by was

  • Resolution set to wontfix
  • Status changed from new to closed

Perhaps this should be at the level of SageObject?: .length() calls .len()? This is irritating but not idiomatic python, so I vote to keep it as is.

I think this would be annoying. It also adds to the clutter when one does X.[tab] on a sage object X. And everybody learns about len(...) in Python pretty soon.

Note: See TracTickets for help on using tickets.