随笔分类 -  python

摘要:from datetime import date, timedelta dt = date.today() - timedelta(5) print('Current Date :',date.today()) print('5 days before Current Date :',dt) 阅读全文
posted @ 2018-11-17 16:59 anobscureretreat 阅读(1351) 评论(0) 推荐(1) 编辑
摘要:def list_sum(num_List): if len(num_List) == 1: return num_List[0] else: return num_List[0] + list_sum(num_List[1:]) print(list_sum([2, 4, 5, 6, 7])) 阅读全文
posted @ 2018-11-16 20:27 anobscureretreat 阅读(2047) 评论(0) 推荐(0) 编辑
摘要:mycode = 'print("hello world")' code = """ def mutiply(x,y): return x*y print('Multiply of 2 and 3 is: ',mutiply(2,3)) """ exec(mycode) exec(code) 阅读全文
posted @ 2018-11-16 20:24 anobscureretreat 阅读(1751) 评论(0) 推荐(0) 编辑
摘要:def is_even_num(l): enum = [] for n in l: if n % 2 == 0: enum.append(n) return enum print(is_even_num([1, 2, 3, 4, 5, 6, 7, 8, 9])) 阅读全文
posted @ 2018-11-16 20:22 anobscureretreat 阅读(1581) 评论(0) 推荐(0) 编辑
摘要:def string_reverse(str1): rstr1 = '' index = len(str1) while index > 0: rstr1 += str1[ index - 1 ] index = index - 1 return rstr1 print(string_reverse('1... 阅读全文
posted @ 2018-11-16 20:20 anobscureretreat 阅读(148) 评论(0) 推荐(0) 编辑
摘要:import collections my_list = [10,10,10,10,20,20,20,20,40,40,50,50,30] print("Original List : ",my_list) ctr = collections.Counter(my_list) print("Frequency of the elements in the List : ",d... 阅读全文
posted @ 2018-11-16 20:14 anobscureretreat 阅读(3298) 评论(0) 推荐(0) 编辑
摘要:def sum_list(items): sum_numbers = 0 for x in items: sum_numbers += x return sum_numbers print(sum_list([1,2,-8])) 阅读全文
posted @ 2018-11-16 20:10 anobscureretreat 阅读(6053) 评论(0) 推荐(1) 编辑
摘要:color = ['Red', 'Green', 'White', 'Black', 'Pink', 'Yellow'] color = [x for (i,x) in enumerate(color) if i not in (0,4,5)] print(color) 阅读全文
posted @ 2018-11-16 20:07 anobscureretreat 阅读(2395) 评论(0) 推荐(0) 编辑
摘要:def multiply_list(items): tot = 1 for x in items: tot *= x return tot print(multiply_list([1,2,-8])) 阅读全文
posted @ 2018-11-16 20:05 anobscureretreat 阅读(988) 评论(0) 推荐(0) 编辑
摘要:def long_words(n, str): word_len = [] txt = str.split(" ") for x in txt: if len(x) > n: word_len.append(x) return word_len print(long_words(3, "Th... 阅读全文
posted @ 2018-11-16 10:33 anobscureretreat 阅读(1669) 评论(0) 推荐(0) 编辑
摘要:def match_words(words): ctr = 0 for word in words: if len(word) > 1 and word[0] == word[-1]: ctr += 1 return ctr print(match_words(['abc', 'xyz', 'aba', '122771'])... 阅读全文
posted @ 2018-11-16 10:29 anobscureretreat 阅读(1274) 评论(0) 推荐(0) 编辑
摘要:def count_range_in_list(li, min, max): ctr = 0 for x in li: if min <= x <= max: ctr += 1 return ctr list1 = [10,20,30,40,40,40,70,80,99] print(count... 阅读全文
posted @ 2018-11-16 10:24 anobscureretreat 阅读(1463) 评论(0) 推荐(0) 编辑
摘要:def common_data(list1, list2): result = False for x in list1: for y in list2: if x == y: result = True return result print(common... 阅读全文
posted @ 2018-11-16 10:17 anobscureretreat 阅读(1115) 评论(0) 推荐(0) 编辑
摘要:nums = [5, 15, 35, 8, 98] for num_index, num_val in enumerate(nums): print(num_index, num_val) 阅读全文
posted @ 2018-11-16 10:12 anobscureretreat 阅读(3156) 评论(0) 推荐(0) 编辑
摘要:def is_Sublist(l, s): sub_set = False if s == []: sub_set = True elif s == l: sub_set = True elif len(s) > len(l): sub_set = False els... 阅读全文
posted @ 2018-11-16 10:09 anobscureretreat 阅读(1928) 评论(0) 推荐(0) 编辑
摘要:输出 阅读全文
posted @ 2018-11-16 01:58 anobscureretreat 阅读(13069) 评论(0) 推荐(2) 编辑
摘要:from random import shuffle color = ['1', '2', '3', '4', '5'] shuffle(color) print(color) 阅读全文
posted @ 2018-11-15 21:23 anobscureretreat 阅读(974) 评论(0) 推荐(0) 编辑
摘要:#Initialize a complex number cn = complex(2,3) print("Complex Number: ",cn) print("Complex Number - Real part: ",cn.real) print("Complex Number - Imaginary part: ",cn.imag) 阅读全文
posted @ 2018-11-15 21:16 anobscureretreat 阅读(13291) 评论(0) 推荐(0) 编辑
摘要:import random print(random.choice('abcdefghijklm')) 阅读全文
posted @ 2018-11-15 21:13 anobscureretreat 阅读(3135) 评论(0) 推荐(0) 编辑
摘要:import random nums = [1, 2, 3, 4, 5, 6, 7] random.shuffle(nums) print(nums) 阅读全文
posted @ 2018-11-15 21:10 anobscureretreat 阅读(7253) 评论(0) 推荐(0) 编辑