Hello **Programmers/Coders,** Today we are going to share ** solutions of Programming problems of HackerRank of Programming Language Python**. At Each Problem with Successful submission with

**all Test Cases Passed,**you will get an score or marks. And after solving maximum problems, you will be getting stars. This will highlight your profile to the recruiters.

In this post, you will find the solution for **Iterables and Iterators in Python-HackerRank Problem**. We are providing the **correct and tested solutions** of coding problems present on **HackerRank**. If you are not able to solve any problem, then you can take help from our Blog/website.

Use “Ctrl+F” To Find Any Questions Answer. & For Mobile User, You Just Need To Click On Three dots In Your Browser & You Will Get A “Find” Option There. Use These Option to Get Any Random Questions Answer.

**Introduction To Python**

**Python **is a widely-used, interpreted, **object-oriented, and high-level programming** language with dynamic semantics, used for general-purpose programming. It was created by **Guido van Rossum**, and first released on **February 20, 1991**.

**Python **is a computer programming language often used to build websites and software, automate tasks, and conduct data analysis. It is also used to create various machine learning algorithm, and helps in Artificial Intelligence. Python is a general purpose language, meaning it can be used to create a variety of different programs and isn’t specialized for any specific problems. This versatility, along with its beginner-friendliness, has made it one of the most-used programming languages today. A survey conducted by industry analyst firm **RedMonk **found that it was the most popular programming language among developers in **2020**.

** Link for the Problem** – Iterables and Iterators in Python – HackerRank Solution

Iterables and Iterators in Python – HackerRank Solution

**Problem:**

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.

To read more about the functions in this module, check out their documentation here.

You are given a list of N lowercase English letters. For a given integer K, you can select any K indices (assume 1-based indexing) with a uniform probability from the list.

Find the probability that at least one of the K indices selected will contain the letter: ‘a’.

#### Input Format :

The input consists of three lines. The first line contains the integer N, denoting the length of the list. The next line consists of N space-separated lowercase English letters, denoting the elements of the list.

The third and the last line of input contains the integer K, denoting the number of indices to be selected.

#### Output Format :

Output a single line consisting of the probability that at least one of the K indices selected contains the letter:’a’.**Note**: The answer must be correct up to 3 decimal places.

#### Constraints :

- 1 <= N <= 10
- 1 <= K < = N

All the letters in the list are lowercase English letters.

#### Sample Input :

4a a c d2

#### Sample Output :

0.8333

#### Explanation :

All possible unordered tuples of length 2 comprising of indices from 1 to 4 are:(1, 2), (1, 3), (1, 4), (2, 3), (2, 4), (3, 4)

Out of these 6 combinations, 5 of them contain either index 1 or index 2 which are the indices that contain the letter ‘a’.

Hence, the answer is 5/6.

Iterables and Iterators in Python – HackerRank Solution

# Iterables and Iterators in Python - Hacker Rank Solution # Python 3 # Enter your code here. Read input from STDIN. Print output to STDOUT # Iterables and Iterators in Python - Hacker Rank Solution START from itertools import combinations N = int(input()) char = input().split() K = int(input()) count = 0; total = 0; for i in combinations(char,K): count += 'a' in i total += 1 print(count/total) # Iterables and Iterators in Python - Hacker Rank Solution END