Iterables and Iterators

Sort by

recency

|

932 Discussions

|

  • + 0 comments

    This problem directing the old version documentation of itertools. It should be updated with the new version. https://docs.python.org/3.8/library/itertools.html

  • + 0 comments

    i saw every answer but no where its mentioned that we need to iterate the list part or n times input

  • + 0 comments

    this work so good and fast!!!

    import itertools
    N =int(input())
    cadena =input().split()
    k=int(input())
    
    print(len(list(itertools.filterfalse(lambda a: 'a' not in a,itertools.combinations(cadena, k))))/(len (list(itertools.combinations(cadena, k)))))
    
  • + 0 comments
    from itertools import combinations
    
    if __name__ == '__main__':
        length,l1,K = int(input()),input().split(),int(input())
        list_combos = list(combinations(l1, K))
        counter1 = 0
        for comb in list_combos:
                if 'a' in comb:
                    counter1 += 1
        print(counter1 / len(list_combos))
    
  • + 0 comments

    I know this is for itertools practice, but without itertools the answer is quite clean. Using 1 minus the multiplicative probability of not choosing 'a'.

    N,s,n = int(input()),input(),int(input())
    x = 1
    b = N-s.count('a')
    for i in range(n):
        x = x*((b-i)/(N-i)) 
    print(1-x)