l1 = ("yellow", "green", "blue", "purple") l2 = ("long", "short") #counts the combinations that can be lade from the items in l1 and the items in l2 def comb_count (list1,list2): count = 0 for item in l1: for item in l2: count += 1 return count #lists the combinations made from l1 and l2abs() def combination_list(list1,list2): combinations = " " for item1 in l1: for item2 in l2: combinations = combinations + str(item1) + " " + str(item2) + ", " return combinations #calculates the permutations of n things taken from a set of size m def permutation_count(m, n): count = 1 while m >= n: count = count * m m = m-1 return count print comb_count(l1,l2) print combination_list(l1,l2) print permutation_count(15,3)
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question