Ad
Lists
Data Structures

Given two numbers, you must create a list of N items that alternates between one and the other.

Example:

If the input is "first_number"=2, "second_number"=5, "elements_on_list"=10,"range_begins_at"=0 the output should be:
[2, 5, 2, 5, 2, 5, 2, 5, 2, 5]

If the input is "first_number"=10, "second_number"=7, "elements_on_list"=23,"range_begins_at"=0 the output should be:
[10, 7, 10, 7, 10, 7, 10, 7, 10, 7, 10, 7, 10, 7, 10, 7, 10, 7, 10, 7, 10, 7, 10]

def generate_binay_list(first_number,second_number,elements_on_list,range_begins_at):
    return [first_number if x%2==0 else second_number for x in range(range_begins_at, elements_on_list)]