Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- combination_list = []
- def combination(alist):
- """
- Recursion method imlementation
- """
- if len(alist) == 2:
- combination_list.append(tuple(alist))
- else:
- for i in alist[1:]:
- combination_list.append((alist[0],i))
- return combination(alist[1:])
- def combination_for(alist):
- """
- For loop method implementaion
- """
- for i in alist[:-1]:
- for j in alist[i+1:]:
- combination_list.append((i,j))
- if __name__ == "__main__":
- alist = [i for i in range(10)]
- # combination(alist)
- combination_for(alist)
- print(combination_list)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement