1.House Password--------------------------------------------- ----------------------------------------
Input: A password as a string.
Output: Is the password safe or not as a boolean or any data type that can be converted and processed as a boolean. In the results you will see the converted results.
Example:
checkio('A1213pokl') == False
checkio('bAse730onE') == True
checkio('asasasasasasasaas') == False
checkio('QWERTYqwerty') == False
checkio('123456123456') == False
checkio('QwErTy911poqqqq') == True
def checkio(data):
if len(data)>=10:
if not(data.isdigit() or data.isalpha() or data.islower() or data.isupper()):
return True
return False
2.The Most Wanted Letter-------------------------------------------- ---------------------------------------
If you have two or more letters with the same frequency, then return the letter which comes first in the latin alphabet. For example -- "one" contains "o", "n", "e" only once for each, thus we choose "e".
Input: A text for analysis as a string.
Output: The most frequent letter in lower case as a string.
Example:
checkio("Hello World!") == "l"
checkio("How do you do?") == "o"
checkio("One") == "e"
checkio("Oops!") == "o"
checkio("AAaooo!!!!") == "a"
checkio("abe") == "a"
def checkio(text):
lower_text = text.lower()
appear_time = {}
for each in lower_text:
if each.islower():
if each not in appear_time:
appear_time[each] = 0
else:
appear_time[each] += 1
array = list(appear_time.items())
array.sort(key=lambda x:x[0])
array.sort(key=lambda x:x[1], reverse=True)
return array[0][0]
3.Non-unique Elements-------------------------------------------- -------------------------------------
You are given a non-empty list of integers (X). For this task, you should return a list consisting of only the non-unique elements in this list. To do so you will need to remove all unique elements (elements which are contained in a given list only once). When solving this task, do not change the order of the list. Example: [1, 2, 3, 1, 3] 1 and 3 non-unique elements and result will be [1, 3, 1, 3].
non-unique-elements
Input: A list of integers.
Output: The list of integers.
Example:
checkio([1, 2, 3, 1, 3]) == [1, 3, 1, 3]
checkio([1, 2, 3, 4, 5]) == []
checkio([5, 5, 5, 5, 5]) == [5, 5, 5, 5, 5]
checkio([10, 9, 10, 10, 9, 8]) == [10, 9, 10, 10, 9]
def checkio(data):
#Your code here```
#It's main function. Don't remove this function
#It's used for auto-testing and must return a result for check.
#replace this for solution
list2=[]
for num in data:
count=data.count(num)
if count>=2:
list2.append(num)
else:pass
return list2
4.Mokey Typing---------------------------------------------- ------------------------------------
You are given some text potentially including sensible words. You should count how many words are included in the given text. A word should be whole and may be a part of other word. Text letter case does not matter. Words are given in lowercase and don't repeat. If a word appears several times in the text, it should be counted only once.
For example, text - "How aresjfhdskfhskd you?", words - ("how", "are", "you", "hello"). The result will be 3.
Input: Two arguments. A text as a string (unicode for py2) and words as a set of strings (unicode for py2).
Output: The number of words in the text as an integer.
Example:
count_words("How aresjfhdskfhskd you?", {"how", "are", "you", "hello"}) == 3
count_words("Bananas, give me bananas!!!", {"banana", "bananas"}) == 2
count_words("Lorem ipsum dolor sit amet, consectetuer adipiscing elit.",
{"sum", "hamlet", "infinity", "anything"}) == 1
def count_words(text, words):
text=text.lower()
count=0
for word in words:
if word in text:
count+=1
return count
You will be the referee for this games results. You are given a result of a game and you must determine if the game ends in a win or a draw as well as who will be the winner. Make sure to return "X" if the X-player wins and "O" if the O-player wins. If the game is a draw, return "D".
A game's result is presented as a list of strings, where "X" and "O" are players' marks and "." is the empty cell.
Input: A game result as a list of strings (unicode).
Output: "X", "O" or "D" as a string.
Example:
checkio([
"X.O",
"XX.",
"XOO"]) == "X"
checkio([
"OO.",
"XOX",
"XOX"]) == "O"
checkio([
"OOX",
"XXO",
"OXX"]) == "D"
def checkio(a):
x=''.join(a)
m=['012','345','678','036','147','258','048','246']
for i in m:
if x[int(i[0])]==x[int(i[1])]==x[int(i[2])]in'XO':
return x[int(i[0])]
return 'D'
6.Pawn Brotherhood----------------------------------------------------------------------------------
A pawn is generally a weak unit, but we have 8 of them which we can use to build a pawn defense wall. With this strategy, one pawn defends the others. A pawn is safe if another pawn can capture a unit on that square. We have several white pawns on the chess board and only white pawns. You should design your code to find how many pawns are safe.
You are given a set of square coordinates where we have placed white pawns. You should count how many pawns are safe.
Input: Placed pawns coordinates as a set of strings.
Output: The number of safe pawns as a integer.
Example:
safe_pawns({"b4", "d4", "f4", "c3", "e3", "g5", "d2"}) == 6
safe_pawns({"b4", "c4", "d4", "e4", "f4", "g4", "e5"}) == 1
def safe_pawns(pawns):
data=['a','b','c','d','e','f','g','h']
result=''
count=0
result_c=''
result_b=''
for x in range(1,9):
result=data[0]+str(x)
if result in pawns:
if (data[1]+str(x-1))in pawns:
count+=1
for y in range(1,9):
result=data[7]+str(y)
if result in pawns:
if (data[6]+str(y-1)) in pawns:
count+=1
for i in range(1,7):
for j in range(1,9):
result=data[i]+str(j)
if result in pawns:
result_c=data[i-1]+str(j-1)
result_b=data[i+1]+str(j-1)
if ((result_c in pawns) or (result_b in pawns)):
count+=1
return count
max(iterable, *[, key]) or min(iterable, *[, key])
max(arg1, arg2, *args[, key]) or min(arg1, arg2, *args[, key])
Return the largest (smallest) item in an iterable or the largest(smallest) of two or more arguments.
If one positional argument is provided, it should be an iterable. The largest (smallest) item in the iterable is returned. If two or more positional arguments are provided, the largest (smallest) of the positional arguments is returned.
The optional keyword-only key argument specifies a function of one argument that is used to extract a comparison key from each list element (for example, key=str.lower).
Input: One positional argument as an iterable or two or more positional arguments. Optional keyword argument as a function.
Output: The largest item for the "max" function and the smallest for the "min" function.
Example:
max(3, 2) == 3
min(3, 2) == 2
max([1, 2, 0, 3, 4]) == 4
min("hello") == "e"
max(2.2, 5.6, 5.9, key=int) == 5.6
min([[1,2], [3, 4], [9, 0]], key=lambda x: x[1]) == [9, 0]
def minSimple(arg1, arg2, key):
if key!=None and key(arg1)key(arg1) or key==None and arg2>arg1: return arg2
return arg1
def max(*args, **kwargs):
key=kwargs.get("key", None) # Extracting key
if len(args)==1: args=list(args[0]) # Adapting arguments
# Comparing arguments, one by one
result=args[0]
for x in range(1,len(args)):
result=maxSimple(result,args[x],key)
return result
Input: String.
Output: Int.
Example:
long_repeat('sdsffffse') == 4
long_repeat('ddvvrwwwrggg') == 3
def long_repeat(line):
"""
length the longest substring that consists of the same char
"""
# your code here
if len(line)==0:return 0
linel=line.lower()
count=0
max_count=0
for i in range(len(line)-1):
if linel[i]==linel[i+1]:
count+=1
else:
max_count=max(max_count,count+1)
count=0
return max(max_count, count+1)
Input: List.
Output: Bool.
Example:
all_the_same([1, 1, 1]) == True
all_the_same([1, 2, 1]) == False
all_the_same(['a', 'a', 'a']) == True
all_the_same([]) == True
from typing import List, Any
def all_the_same(elements: List[Any]) -> bool:
# your code here
return len(set(elements))<2