Basic List Functions Flashcards

1
Q

head

A

Takes a list and returns its first element

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

tail

A

Takes a list and returns the list after removing the head

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

init

A

Takes a list and returns all elements except the last as a list

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

last

A

Takes a list and returns the last element

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

length

A

returns the length of a given list

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

null

A

Checks if the list is empty

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

reverse

A

reverses the list

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

take

A

Params: a number and a list This function extracts given number of elements from the list. For example, take 2 [1,2,3,4] will return [1,2]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

drop

A

Similar to take, but drops number of elements from the beginning of the list

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

maximum

A

takes a list, put it in order and returns the maximum element

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

minimum

A

Similar to maximum but returns the minimum element

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

sum

A

takes a list of numbers and returns the sum of all elements

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

product

A

similar to sum and returns product of all elements

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

elem

A

takes a thing and a list and returns if the ‘thing’ is an element of the list

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

cycle

A

Takes a list and cycles it into an infinite list.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

repeat

A

takes an element and makes an infinite list with just that element

17
Q

replicate

A

takes a number and an element; returns a list of length number in which the element is repeated

18
Q

Evaluate length []

A

returns error

19
Q

Evaluate take 5 [1,2,3]

A

returns [1,2,3]

20
Q

Evaluate take (-1) [1,2,3]

A

returns []

21
Q

range specifier

A

..

22
Q

provide an example list using range specifier

A

[1..20] specifies list of all numbers from 1 to 20

23
Q

Create a list using every 5th number from 1 to 100

A

[5,10..100]

24
Q

specify a list using range in decreasing order of numbers

A

[20,19..1]

25
Q

caution in using floating point numbers in ranges

A

do not use them

26
Q

Give an example of infinite range

A

[1,2..]

27
Q

create a list of first 25 multiples of 7

A

[7,14,..25*7]

take 25 [7,14..]