티스토리 뷰
* NATO Ponetic Alphabet이 정의된 csv를 이용함.
nato_phonetic_alphabet.csv
0.00MB
#TODO 1. using csv file, Create a dictionary in this format like:
#{"A": "Alfa", "B": "Bravo"}
data = pandas.read_csv("./nato_phonetic_alphabet.csv")
data_dict_comprehension = { row.letter:row.code
for (index,row) in data.iterrows()
}
#print(data_dict_comprehension)
#TODO 2. Create a list of the phonetic code words from a word that the user inputs.
word = input("Enter a word: ").upper()
phonetic_word_lists = []
for i in word:
#phonetic_word_lists.append(code for (letter,code) in data_dict_comprehension.items() if i.upper() == letter)
for (letter,code) in data_dict_comprehension.items():
if i == letter:
phonetic_word_lists.append(code)
print(phonetic_word_lists)
Enter a word: kioeom
['Kilo', 'India', 'Oscar', 'Echo', 'Oscar', 'Mike']
* TODO 2를 다시 간단하게.
> 리스트를 별도로 지정하는 것도 필요없고
> for문을 중복으로 돌리는 것도 필요없고
> word의 알파벳과 비교도 간단히
#TODO 2. Create a list of the phonetic code words from a word that the user inputs.
word = input("Enter a word: ").upper()
phonetic_word_lists = [ data_dict_comprehension[letter] for letter in word ]
print(phonetic_word_lists)
Enter a word: korea
['Kilo', 'Oscar', 'Romeo', 'Echo', 'Alfa']
'Test > Python(20220101~)' 카테고리의 다른 글
Days27. Many positional Arguments (0) | 2022.04.08 |
---|---|
Days27. tkinter, *args, **kwargs, GUI (0) | 2022.03.27 |
Days26. Dictionary Comprehension (0) | 2022.03.17 |
Days26. List Comprehension (2) | 2022.03.14 |
cf. Get mouse click coordinates in Python turtle (0) | 2022.03.12 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- EXA
- dezoomify
- vmware.powercli
- 정렬
- 변수화
- cloud-init
- Join
- 스토리지
- 3par
- 배열
- storage
- 중복제거
- fromkeys
- dp-2
- 대소문자
- powercli
- artandculture
- insert
- sysprep
- dp-1
- set()
- powershell
- 차집합
- LIST
- 읽어오기
- virt-sysprep
- vmware
- 부동없이
- exadata
- oracle
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
글 보관함