(nth integer list)
Determine the nth item in the list.
Like car and cdr, the function nth is used to separate an element from a list. This function is much easier to use in long lists to isolate a single element.
The argument integer represents the number of the item to isolate. Remember that the first item in the list is numbered 0, so that when you want the third item you use 2. When integer is larger than the number of items (actually, number - 1 items) in the list, the nth function returns nil.
Examples
| Code | Returns |
|---|---|
| (setq b '(1 2 3 4 5 4 3 2 1)) | (1 2 3 4 5 4 3 2 1) |
| (nth 4 b) | 5 |
| (setq c '("one" "two" "three" "four")) | (one two three four) |
| (nth 2 c) | three |
| (nth 5 c) | nil |
en
italiano
čeština
Deutsch
français
hrvatski
magyar
polski
српски
русский
中文
中文
한국어
español