how to talk about items

A forum for general discussion of the Python programming language.

how to talk about items

Postby darter » Mon Jan 27, 2014 3:46 am

This is a natural language question.

If I have b=[3,4,5,6], and I told you to print the first item you'd probably produce a 3, which has an index of zero. It appears first in the list.

But how do we succinctly tell someone to print 4 by referring to its index?

Saying: 'print the item with index one' is not succinct. I need a shorter way.

Any ideas?
darter
 
Posts: 7
Joined: Sun Feb 10, 2013 5:19 am

Re: how to talk about items

Postby Mekire » Mon Jan 27, 2014 3:52 am

You can say:
Code: Select all
Print the second item.
or
Code: Select all
Print the item at index one.

Python is a 0 start index language (which is a good thing; 1 start index is horrible) so that is as good as it gets.

Not sure what you want.
-Mek
User avatar
Mekire
 
Posts: 1033
Joined: Thu Feb 07, 2013 11:33 pm
Location: Amakusa, Japan

Re: how to talk about items

Postby metulburr » Mon Jan 27, 2014 5:23 am

But how do we succinctly tell someone to print 4 by referring to its index?

It depends on who you are talking to. If its a programmer, you can most likely assume that they know that lists/arrays start with index 0, however if its not a programmer, you might as well just ignore the fact when communicating to them that they start at index 0.

Saying: 'print the item with index one' is not succinct. I need a shorter way.

print b[1]

for example:
Code: Select all
options = ['1) Play', '2) Options', '3) Exit']

If they want to select Play, they are going to insert 1, however the true value to call is 0, options[0]. Since python takes input as a string, you can just check the string against a string value. However in a langauge like c++, where the input most likely would be an int, you would just subtract 1 from the users value to get the index.

Like Mekire said, you really didnt specify what exactly you are talking about, so its hard to pinpoint an example/explanation.
New Users, Read This
OS Ubuntu 14.04, Arch Linux, Gentoo, Windows 7/8
https://github.com/metulburr
steam
User avatar
metulburr
 
Posts: 1513
Joined: Thu Feb 07, 2013 4:47 pm
Location: Elmira, NY

Re: how to talk about items

Postby stranac » Mon Jan 27, 2014 8:39 am

metulburr wrote:If its a programmer, you can most likely assume that they know that lists/arrays start with at index 0

Hey, that's not fair.
What about poor fortran people? Or cobol people? Or matlab people...
Friendship is magic!

R.I.P. Tracy M. You will be missed.
User avatar
stranac
 
Posts: 1218
Joined: Thu Feb 07, 2013 3:42 pm

Re: how to talk about items

Postby Kebap » Mon Jan 27, 2014 11:35 am

In natural language, indices start at number 1.

So item "4" in your example would be the second item.
Learn: How To Ask Questions The Smart Way
Join the #python-forum IRC channel on irc.freenode.net and chat with uns directly!
Kebap
 
Posts: 400
Joined: Thu Apr 04, 2013 1:17 pm
Location: Germany, Europe

Re: how to talk about items

Postby Mekire » Mon Jan 27, 2014 12:02 pm

Kebap wrote:In natural language, indices start at number 1.

Look at a ruler and tell me which number it starts with. The first inch/centimeter on a ruler is between zero and one. How is referring to the item from where it ends more natural than where it begins?

Yes, sequences start with the "first" item. But using all the natural language you want that is still index zero. The four is absolutely the second item; just as it is absolutely located at the 1st index (I choose to ignore the languages that decided to define it as otherwise).

stranac wrote:What about poor fortran people? Or cobol people? Or matlab people...

@Stranac: Lua too, apparently.

My opinion,
-Mek
User avatar
Mekire
 
Posts: 1033
Joined: Thu Feb 07, 2013 11:33 pm
Location: Amakusa, Japan

Re: how to talk about items

Postby Kebap » Mon Jan 27, 2014 12:32 pm

Mekire wrote:Look at a ruler and tell me which number it starts with. The first inch/centimeter on a ruler is between zero and one.

See "the first inch/centimeter", you call it the first. Not the zero-est or something. I agree with the ruler example though, where the items itself have numbers attached to them. Maybe my generalisation has errors.
Learn: How To Ask Questions The Smart Way
Join the #python-forum IRC channel on irc.freenode.net and chat with uns directly!
Kebap
 
Posts: 400
Joined: Thu Apr 04, 2013 1:17 pm
Location: Germany, Europe

Re: how to talk about items

Postby Mekire » Mon Jan 27, 2014 12:40 pm

I do call it the first, yes.

But a baby is not 1 year old (in English speaking countries) during their first year of life.

They become 1 year old after their first year is complete.

(Note: Some Asian countries differ in this and a newborn is considered 1 at birth but that isn't the point).

-Mek
User avatar
Mekire
 
Posts: 1033
Joined: Thu Feb 07, 2013 11:33 pm
Location: Amakusa, Japan

Re: how to talk about items

Postby metulburr » Mon Jan 27, 2014 1:08 pm

(Note: Some Asian countries differ in this and a newborn is considered 1 at birth but that isn't the point).

really? thats quite odd.
New Users, Read This
OS Ubuntu 14.04, Arch Linux, Gentoo, Windows 7/8
https://github.com/metulburr
steam
User avatar
metulburr
 
Posts: 1513
Joined: Thu Feb 07, 2013 4:47 pm
Location: Elmira, NY

Re: how to talk about items

Postby Mekire » Mon Jan 27, 2014 1:15 pm

Heh... I didn't actually expect there to be a Wikipedia article on it but...

Here you go.

-Mek
User avatar
Mekire
 
Posts: 1033
Joined: Thu Feb 07, 2013 11:33 pm
Location: Amakusa, Japan


Return to General Discussions

Who is online

Users browsing this forum: No registered users and 3 guests