Q:

Prolog list adding

--the question has been edited--
Using this data, I need to create a list:
team(milan,1).
team(napoli,2).
team(lazio,3).
team(roma,4).
team(inter,4).
team(juventus,5).

So, given a query like:
check([milan,lazio,roma,inter]).

make a new list with their respective team number.
X=[1,3,4,4]

What I'm trying to do is creating a list, adding elements one at a time.
check([H|T]) :-
 team(H,R),
 append([R],_, X),
 check(T).

Could someone help me complete this?

A:

You need to find all the team numbers for which the name of the team is a member of the list of team names that you are interested in:
?- findall(Number, (
                   team(Name, Number),
                   member(Name, [milan, lazio, roma, inter])), Numbers).
Numbers = [1, 3, 4, 4].

To return the numbers in a given order, just apply member/2 before team/2, in this case member/2 generates names (in the given order), and team/2 maps them to numbers:
?- findall(Number, (
                   member(Name, [lazio, milan, inter]),
                   team(Name, Number)), Numbers).
Numbers = [3, 1, 4].

