Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """T07."""
- def organise_by_first_symbol(strings: list) -> dict:
- """
- Return dict where key the is a symbol and the value is a list of words starting with this symbol.
- organise_by_first_symbol(["hello", "word", "world", "welcome", "yes"]) =>
- {'h': ['hello'], 'w': ['word', 'world', 'welcome'], 'y': ['yes']}
- :param strings: List of strings
- :return: Dict with starting symbol and corresponding words.
- """
- new = {}
- dic = []
- for i in strings:
- dic[:] = i
- if dic[0] in new:
- new[dic[0]].append(i)
- else:
- new[dic[0]] = [i]
- return new
- def count_symbol_appearances(stringy: str) -> dict:
- """
- Return dict where key is the symbol and the value is the count this symbol is present in the string.
- count_symbol_appearances("hello hi") => {'h': 2, 'e': 1, 'l': 2, 'o': 1, ' ': 1, 'i': 1}
- :param stringy: String to be processed.
- :return: Dict with symbol counts.
- """
- new = {}
- dic = []
- dic[:] = stringy
- for letter in dic:
- if letter not in new:
- new.setdefault(letter, int(1))
- else:
- new[letter] = new[letter] + int(1)
- return new
- def get_unique_values(dictionary: dict) -> list:
- """
- Return the list of unique dict values.
- get_unique_values({1: "a", 2: "b"})) => ["a", "b"]
- get_unique_values({1: "a", 2: "b", 3: "a"})) => ["a", "b"]
- The order is not important.
- :param dictionary: Dict to be processed.
- :return: List of unique values.
- """
- new = []
- for letter in dictionary:
- if dictionary[letter] in new:
- continue
- else:
- new.append(dictionary[letter])
- return new
- def count_symbol_appearances_2(stringy: str) -> dict:
- """
- Return dict where key is a count and value is a list of symbols which appear this many times in the input string.
- count_symbol_appearances_2("hello") => {1: ['e', 'o', 'h'], 2: ['l']}
- count_symbol_appearances_2("abcaba") => {2: ['b'], 1: ['c'], 3: ['a']}
- :param stringy: String to be processed
- :return: Dict with counts and list of symbols
- """
- new = {}
- dic1 = {}
- dic = []
- dic[:] = stringy
- for i in stringy:
- dic1[i] = stringy.count(i)
- for o in dic1:
- if dic1[o] in new:
- new[dic1[o]].append(o)
- else:
- new[dic1[o]] = [o]
- return new
- def debug_numbers_in_string(stringy: str) -> list:
- """вю."""
- numbers = []
- for i in stringy:
- if i.isdigit():
- numbers.append(int(i))
- return numbers
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement