반응형 python27 List comprehension Overview 파이썬에서 List comprehension의 정의는 list를 간결한 방법으로 생성하는 것을 의미한다. 아래와 같은 dev_info의 문자열로 구성된 data를 list로 만들고자 하는데 list comprehension 기능을 사용하지 않으면 두 줄 정도의 코드가 필요하다. 반대로 list comprehension을 이용한다면 한 줄로 표현할 수 있다. List를 생성함과 동시에 값을 할당하는 것이다. # [List comprehension 미사용] dev_info = ' 1.1.1.1, username, password ' item_list = [] for elem in dev_info.split(','): item_list.append(elem.strip()) # [List com.. 2020. 3. 30. SecureCRT python script to update hostname and banner This script is to update hostname and banner of cisco swtiches especially IOS. ****** # $language = "python" # $interface = "1.0" # # Author: Ethan Park # Date: 3/2/2020 # This script reads a csv file which contains hostname, IP address and a model # It updates hostname and banner section import csv import math def updateBanner(host, model): hostLength = int(math.ceil((35 - len(host)) / 2)) mode.. 2020. 3. 4. Python Multiple return values (Tuple, Dict) # Question:# Write a program that accepts a sentence and calculate the number #of letters and digits.# Suppose the following input is supplied to the program:# hello world! 123# Then, the output should be:# LETTERS 10# DIGITS 3 [Tuple 이용] def countingStr(sentence): countNum = 0 countChar = 0 for i in range(len(sentence)): if((65 2018. 8. 23. List 자료형의 Join함수 사용하기 Question:Write a program which will find all such numbers which are divisible by 7 but are not a multiple of 5,between 2000 and 3200 (both included).The numbers obtained should be printed in a comma-separated sequence on a single line. def divisibleSevenNotDivisibleFive(): listOfNumber = "" # Range: 2000 ~ 3200 for i in range(2000, 3201): if((i % 7 == 0) and (i % 5 != 0)): listOfNumber = listOfN.. 2018. 8. 21. 이전 1 2 3 4 5 6 7 다음 반응형