Iterables and Iterators

Sort by

recency

|

922 Discussions

|

  • + 0 comments

    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

  • + 0 comments

    Here is HackerRank Iterables and Iterators in python solution - https://programmingoneonone.com/hackerrank-iterables-and-iterators-solution-in-python.html

  • + 0 comments

    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)))

  • + 1 comment

    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))

  • + 0 comments
    from itertools import combinations
    
    # Input
    n = int(input())                 
    letters = input().split()       
    k = int(input())                
    combs = list(combinations(letters, k))
    
    countwitha=sum([1 for comb in combs if "a" in comb])
    ratio=countwitha/len(combs)
    print(f"{ratio:.3f}")