← Problems87. Split a tag list into rowsEasyPySpark
00:00 / 15:00

Split a tag list into rows

Easy100% solve itAsked at Deloitte, TCS

Tags arrive as one comma-separated string per article, typed by hand. The warehouse wants them as a bridge table.

Input

articles article_id bigint tags string -- comma separated, or null

Output

One row per article and tag, with the columns article_id and tag.

  • Split on commas, then trim each tag.
  • Drop anything that is empty once trimmed.
  • The same tag twice on one article is one row.
  • An article with no usable tag contributes no rows at all.

Example

article_idtags
1spark, sql ,python
3a,,b, a
article_idtag
1spark
1sql
1python
3a
3b

Constraints

  • Trim after splitting. Only the split knows where each tag begins.
  • Case is content. Delta, delta and DELTA are three different tags.
  • Row order is not graded. Column names and their order are.

Example 1spaces around the separators

Input · articles
tagsarticle_id
spark, sql ,python1
etl2
Output
article_idtag
1spark
1sql
1python
2etl

Example 2empty segments and a repeat

Input · articles
tagsarticle_id
a,,b, a3
4
Output
article_idtag
3a
3b

Topics

array handlingdata quality

Similar problems

Community-reported interview topic. Not an official company question and no affiliation is implied.

solution.py
Loading editor…
Draft not saved yet · Spaces 4 · UTF-8⌘↵ run ⌘⇧↵ submit
Nothing run yet

Run against the public tests, or submit to score against all of them.