5 yıl tecrübeli python developer arayan bir firmanın live coding soruları
iki dosya var main.py da bir import hatası var onu düzelttikten sonra test_functions daki fonksiyonların içi doldurulacak
main.py
from test_functions import sum_even_numbers, char_frequency, is_palindrome
# Test 0
# This file fails to execute fix the error !
# Test 1
print(char_frequency('hellow my fiend'))
# Test 2
print(sum_even_numbers([1, 2, 3, 4, 5, 6]))
# Test 3
print(is_palindrome("A man, a plan, a canal: Panama")) # True
print(is_palindrome("race a car")) # False
test_functions.py
def sum_even_numbers(lst):
#Write a function to return the sum of all even numbers in a list.
return
# Test
#print(sum_even_numbers([1, 2, 3, 4, 5, 6])) # Expected output 12
#print(sum_even_numbers([]))
def char_frequency(s):
#Write a function to count the frequency of each character in a string and return a dictionary.
return
def is_palindrome(s):
# Write a function to check if a string is a palindrome (reads the same backward as forward).
# Ignore case and non-alphanumeric characters.
return
def guess_result():
a = [1, 2, 3]
b = [1, 2, 3]
print(a == b)
print(a is b)
son fonksiyonda bir şey yazmıyorsunuz sonuç ne döner diye soruyorlar.
def sum_even_numbers(lst):
#Write a function to return the sum of all even numbers in a list.
return sum([num for num in lst if num % 2 ==0])
ben daha uzun yazmıştım daha kısa nasıl yazılır diye sordular
def char_frequency(s):
#Write a function to count the frequency of each character in a string and return a dictionary.
return {char: s.count(char) for char in s}
ben count fonksiyonunu hatırlamadığım için döngü ile buldum.
def is_palindrome(s):
# Write a function to check if a string is a palindrome (reads the same backward as forward).
# Ignore case and non-alphanumeric characters.
sl = [char.lower() for char in s if char.isalnum()]
for i in range(len(sl)):
if not sl[i]==sl[-i-1]:
return False
return True
bunda da listeye çevirmeden yapılacak bir çözüm daha iyi olabilirdi.
print(a == b) -> True
print(a is b) -> False