DefaultDict Tutorial

Sort by

recency

|

1066 Discussions

|

  • + 0 comments
    n, m = list(map(int, input().split()))
    a = [letter for letter in (input() for _ in range(n))]
    
    print("\n".join(
        " ".join(str(i + 1) for i in range(n) if a[i] == letter) or "-1"
        for letter in (input() for _ in range(m))
    ))
    
  • + 0 comments

    Can i use this on [fmwhsapp.com](https://fmwhsapp.com/ ) blog?

  • + 0 comments

    Specify that the default value is provided by a factory function when the defaultdict is created. online cricket id

  • + 0 comments
    n, m = map(int, input().strip().split(" "))
    A = []
    for _ in range(n):
        A.append( input().strip() )
    
    for _ in range(m):
        str = input().strip() 
        l = list( [index + 1 for index, value in enumerate(A) if value == str] )
        print(-1) if len(l) == 0 else print(*l)
    
  • + 0 comments

    from collections import defaultdict

    n, m = list(map(int,input().split())) Groups = defaultdict(list)

    for i in range(n): Groups['A'].append(input())

    for i in range(m): Groups['B'].append(input())

    for word in Groups['B']: indices = [] for i, each in enumerate(Groups['A']): if word == each: indices.append(i+1) if indices: print(*indices) else: print(-1)