Iterables and Iterators

Sort by

recency

|

933 Discussions

|

  • + 0 comments
    from itertools import combinations
    
    length = int(input())
    s = input().split()
    k = int(input())
    count = 0
    for tup in combinations(s,k):
        if any(elem == 'a' for elem in tup):
            count += 1
    
    print(count / len(list(combinations(s,k))))
    
  • + 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))