We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Iterables and Iterators
Iterables and Iterators
Sort by
recency
|
922 Discussions
|
Please Login in order to post a comment
Great for anyone looking to write cleaner, more Pythonic code. Thanks to the community for sharing tips and examples—it makes learning so much smoother! Fairplay24 pro sign up
Here is HackerRank Iterables and Iterators in python solution - https://programmingoneonone.com/hackerrank-iterables-and-iterators-solution-in-python.html
import math
N = int(input()) all_strs = input().split() K = int(input())
non_a_num = len(list(filter(lambda x: x!= "a", all_strs))) if non_a_num < K: print(1) else: print(1 - (math.factorial(non_a_num)/math.factorial(non_a_num-K))/(math.factorial(N)/math.factorial(N-K)))
except 2 test cases all pass can any body help me with this code from itertools import combinations as p n = int(input()) s = sorted(input().split()) m = int(input()) a = list(p(s,m)) count = 0 for i in a : if s[1] in i or s[0] in i: count += 1 print(count/len(a))