fork download
  1. #test data
  2. lines = ['razrazraz,rabotay', 'vilkoy, rabotay, razrazraz', 'kak ya vilkoy chistit to budu?']
  3. uniWords = {0: 'raz', 1:'vilkoy', 2: 'bratishka', 3: 'rabota'}
  4.  
  5.  
  6. matrix = [[0 for col in uniWords] for row in lines]
  7.  
  8.  
  9. for index, line in enumerate(lines):
  10. for key, val in uniWords.items():
  11. matrix[index][key] = line.count(val)
  12.  
  13. print(matrix)
Success #stdin #stdout 0.02s 9984KB
stdin
Standard input is empty
stdout
[[3, 0, 0, 1], [3, 1, 0, 1], [0, 1, 0, 0]]