본문 바로가기

분류 전체보기11

[Beginner] Code Challenge: Dictionaries 2 1. Word Length Dict (길이 계산) write a function that creates a new dictionary based on a list of strings keys = strings / values = length of each of the words 방법 1. def word_length_dictionary(words): word_lengths = {} for word in words: word_lengths[word] = len(word) return word_lengths 방법 2 - 방법 1 간소화 def word_length_dictionary(words): return {word:len(word) for word in words} 해설지에는 방법1 제시했음 2. Fr.. 2022. 8. 13.
[Beginner] Code Challenge: Dictionaries 1 1. Sum Values sum up all the values in the dictionary def sum_values(my_dictionary): value_sum = 0 for value in my_dictionary.values(): value_sum += value return value_sum 2. Even Keys Next, we are going to do something similar, but we are going to use the keys in order to retrieve the values. Additionally, we are going to only look at every even key within the dictionary. def sum_even_keys(my_d.. 2022. 8. 13.
[Beginner] Code Challenge: Strings 1. Check Name 인사말에 유저 이름이 들어가있는지 확인하는 function 만들기 2 function parameters, both strings, one is a sentence and one a name 이름이 인사말에 있다면, return True (※ 대소문자 상관없이 확인할 수 있게 할 것) 내가 처음 작성한 코드는 def check_for_name(sentence, name): lowered_sentence = sentence.lower() lowered_name = name.lower() if lowered_name in lowered_sentence: return True else: return False 이었고 결과값에는 문제는 없었다. 하지만 답을 확인해보니 아래처럼 더 짧고 .. 2022. 8. 13.