Preceding number list X69413


Statement
 

pdf   zip

html

Write a function pre_number_list(n, f) that given an integer n and a list of integers f, returns the list formed by the numbers in f that appear just before each ocurrence of n in f. The order of appearance of the numbers in the resulting list must preserve the original order.

Sample session
>>> pre_number_list(7, [7, 10, 7, 5, 8, 7])
[10, 8]
>>> pre_number_list(0, [-3 , 0])
[-3]
>>> pre_number_list(0 , [0, -3])
[]
>>> pre_number_list(6, [5, 6]) + pre_number_list(6, [1, 6, 2, 6])
[5, 1, 2]
>>> pre_number_list(7, [5])
[]
>>> pre_number_list(6, [])
[]
>>> pre_number_list(7, [7, 7, 7])
[7, 7]
Information
Author
ProAl
Language
English
Official solutions
Python
User solutions
Python