Embercode
✕
StringsQuick quiz

CSV and search

8 questions. Covers Naive substring search in Python.

Questions 1 to 5 of 8

  1. 1. What does this program print? ``python print('Ada,,London,'.split(',')) print(len('Ada,,London,'.split(','))) ``
  2. 2. What does 'a b c '.split() return? The text has two spaces after the a and one space at the end.
  3. 3. What does this program print? ``python import csv row = next(csv.reader(['"Smith, John",42,Leeds'])) print(len(row)) print(row[0]) ``
  4. 4. Which expression is the worst-case number of character comparisons for naive substring search, when the text has n characters and the pattern has m characters?
  5. 5. What does this program print? ``python comparisons = 0 def naive_search(text, pattern): global comparisons n = len(text) m = len(pattern) for start in range(n - m + 1): j = 0 while j < m: comparisons += 1 if text[start + j] != pattern[j]: break j += 1 if j == m: return start return -1 at = naive_search('aaab', 'aab') print(f'found at {at} after {comparisons} comparisons') ``

5 question(s) left on this page.