Comparisment

   - compare programming languages by example

38

List access

Access elements of a linked list.

Created by sam

Add a new answer

Either add an answer for a new language or add an alternative solution.
A description is only necessary when the code is not suitably 'obvious' or to justify an alternative approach.

Haskell

two :: Int
two = [1,2,3,4,5] !! 1

'!!' is an unsafe index operator which is only defined for non-empty lists.

Created by: sam

Edit this answer

Edit the language, code and description simultaneously.

Python

two = [1,2,3][1]

When square brackets appear after a list, they denote an index.

Created by: sam

Edit this answer

Edit the language, code and description simultaneously.