Question: I have to search for a word from a file containing multiple songs, separated by a specific string, and display every song title that contains the word in its lyrics.

The file has the following format:

```none
xxxxxxxxxx

song title

Lyrics

xxxxxxxxxx

Song Title

Lyrics

[...]

```

The code I wrote is:

```
#include <stdio.h>
#include<string.h>

/* Note: pif will be function needed to search a word within a generic string */

int main(){
  FILE *fp=fopen("file.txt", "r");
  char line[200],search_string[]="xxxxxxxxxx",word[20],buff[200];
  int cnt=0,flag=0;
  gets(word);
  if (!fp)
    return -1;
  printf("\n\tSongs Containing %s: ", word);
  cnt=0;
  while ( fgets ( line, 200, fp ) != NULL ) /*read a line*/
  {
    if(strstr(line,search_string)){ /*find the separator*/
      fgets(line,200,fp);/*go ahead reading*/
      strcpy(buff,line); /*save the title, which is the very next line after the separator*/
      while(!strstr(line,search_string)){ /* while the lyrics do not match with another 
                                             separator go ahead reading*/
        fgets(line,200,fp);
        if(pif(line,word)) /*using the defined *pif* function (required), I'd find *word* 
                             within the line */
           flag=1;
      }
      if(flag)
         printf("%s", buff);

    }
  }
  fclose(fp);

  return 1;
}

```

Is there anyway I can make this whole stuff working? The output displays each song titles instead of specific ones.

Answer: 
Most functions in `datatable`, including `sum()`, will automatically apply across all columns if given a multi-column set as an argument. Thus, R's `lapply(.SD, sum)` becomes simply `sum(.SD)`, except that there is no `.SD` in python, instead we use the `f` symbol and combinations. In your case, `f[:]` will select all columns other than the groupby, so it is basically equivalent to `.SD`.

Secondly, all unary functions (i.e. functions that act on a single column, as opposed to binary functions like `+` or `corr`) pass-through the names of their columns. Thus, `sum(f[:])` will produce a set of columns with the same names as in `f[:]`.

Putting this all together:

```py
>>> from datatable import by, sum, f, dt

>>> DT_X[:, sum(f[:]), by(f.issue)]
   | issue  speech  narrative  thought
-- + -----  ------  ---------  -------
 0 | cs-1        1          2        0
 1 | cs-2        2          0        2
 2 | cs-3        2          2        2

[3 rows x 4 columns]

```
Here is a one of recommended solution by @Erez.

```
DT_X[:,{name: dt.sum(getattr(f, name)) for name in ['speech', 'narrative', 'thought']},
by(f.issue)]

```

and output:-

```
Out[7]: 
   | issue  speech  narrative  thought
-- + -----  ------  ---------  -------
 0 | cs-1        1          2        0
 1 | cs-2        2          0        2
 2 | cs-3        2          2        2

[3 rows x 4 columns]

```