Q:

Python - How to extract numbers in list A depending on list B?

My purpose is:
For every element in B, I want to create a list, in which it contains elements of list B and smaller elements(than B element) in list A.
I tried two for loops, however, I do not know how to finish this work :
A=[1,2,3,4,5,6,7,8,9]
B=[3,4,5]
C=[]
for i in B:
    for r in A:
        if i>=r:
            C.append(r)

I expect a result like this:
[[3,1,2,3],[4,1,2,3,4],[5,1,2,3,4,5]]

Any suggestions? 

A:

Try this:
for i in B:
    new_list = [i]  # inner list starting with the elmt from B
    for r in A:
        if i >= r:
            new_list.append(r)  # append to inner list
    C.append(new_list)  # finally append inner list to C

