# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
# ---

# Task 1:
# Count the number of occurrences of certain letters in a string.
#
# We want to know the counts of each of a set of letters in the input string. For instance, we might want to know how many as, xs, and js there are.
#
# You'll return the list of requested counts as an array.
#
# If letters is an empty string, return an empty array.

def solution(s, letters):
    d = {}
    for letter in letters:
        d[letter] = 0
        
    for char in s:
        if char in d:
            d[char] += 1
        else:
            d[char] = 1
            
    result = []
    for letter in letters:
        result.append(d[letter])
    return result


# Task 2:
#
# Codewriting
#
# Description
# Count all the words in a string, then produce a new string when the count of each word in parentheses follows each word.
#
# If the string is empty, return an empty string.

def solution(s):
    words = s.split()
    d = {}
    for word in words:
        if word not in d:
            d[word] = 1
        else:
            d[word] += 1
            
    results = []
    for word in words:
        results.append(f"{word}({d[word]})")
    return ' '.join(results)


# Task 3:
# Given a string of lowercase words separated by single spaces, return a string with all duplicate words removed. However, the first occurrence of a duplicate word should be left in place; only the subsequent duplicates should be removed.
#
# If the string is empty, return an empty string.

def solution(s):
  words = s.split()
  result = []
  for word in words:
    if word in result:
      pass
    else:
      result.append(word)
  return ' '. join(result)

StarcoderdataJupyterScriptsDedupFiltered