HackerRank Python - Iterables and Iterators

The itertools module standardizes a core set of fast, memory efficient tools that are useful by themselves or in combination. Together, they form an iterator algebra making it possible to construct specialized tools succinctly and efficiently in pure Python.

  1. # Enter your code here. Read input from STDIN. Print output to STDOUT
  2. from itertools import combinations
  3. n = int(input())
  4. array = input().split()
  5. k = int(input())
  6. comb_list = list(combinations(array, k))
  7. a_list = [e for e in comb_list if 'a' in e]
  8. print(len(a_list) / len(comb_list))


Codesadda.com is your home of programming solutions, tutorials, video tutorials and much more. Sign Up for our weekly newsletter to get update about new content.

Like us on Facebook | Connect with us on LinkedIn | Subscribe our Channel on Youtube