好用到哭!你需要立刻學會的20個Python程式碼段
# Reversing a string using slicing my_string = "ABCDE" reversed_string = my_string[::-1] print(reversed_string) # Output # EDCBA
my_string = "my name is chaitanya baweja" # using the title() function of string class new_string = my_string.title() print(new_string) # Output # My Name Is Chaitanya Baweja
my_string = "aavvccccddddeee" # converting the string to a set temp_set = set(my_string) # stitching set into a string using join new_string = .join(temp_set) print(new_string)
n = 3 # number of repetitions my_string = "abcd" my_list = [1,2,3] print(my_string*n) # abcdabcdabcd print(my_list*n) # [1,2,3,1,2,3,1,2,3] import streamlit as st
n = 4 my_list = [0]*n # n denotes the length of the required list # [0, 0, 0, 0]
# Multiplying each element in a list by 2 original_list = [1,2,3,4] new_list = [2*x for x in original_list] print(new_list) # [2,4,6,8]
a = 1 b = 2 a, b = b, a print(a) # 2 print(b) # 1
string_1 = "My name is Chaitanya Baweja" string_2 = "sample/ string 2" # default separator print(string_1.split()) # [ My , name , is , Chaitanya , Baweja ] # defining separator as / print(string_2.split( / )) # [ sample , string 2 ]
list_of_strings = [ My , name , is , Chaitanya , Baweja ] # Using join with the comma separator print( , .join(list_of_strings)) # Output # My,name,is,Chaitanya,Baweja
my_string = "abcba" m if my_string == my_string[::-1]: print("palindrome") else: print("not palindrome") # Output # palindrome
# finding frequency of each element in a list from collections import Counter my_list = [ a , a , b , b , b , c , d , d , d , d , d ] count = Counter(my_list) # defining a counter object print(count) # Of all elements # Counter({ d : 5, b : 3, a : 2, c : 1}) print(count[ b ]) # of individual element # 3
print(count.most_common(1)) # most frequent element # [( d , 5)]
From collections import Counter str_1, str_2, str_3 = "acbde", "abced", "abcda" cnt_1, cnt_2, cnt_3 = Counter(str_1), Counter(str_2), Counter(str_3) if cnt_1 == cnt_2: print( 1 and 2 anagram ) if cnt_1 == cnt_3: print( 1 and 3 anagram )
a, b = 1,0 try: print(a/b) # exception raised when b is 0 except ZeroDivisionError: print("division by zero") else: print("no exceptions raised") finally: print("Run this always")
my_list = [ a , b , c , d , e ] for index, value in enumerate(my_list): print( {0}: {1} .format(index, value)) # 0: a # 1: b # 2: c # 3: d # 4: e
import sys num = 21 print(sys.getsizeof(num)) # In Python 2, 24 # In Python 3, 28
dict_1 = { apple : 9, banana : 6}
dict_2 = { banana : 4, orange : 8} combined_dict = {**dict_1, **dict_2} print(combined_dict) # Output # { apple : 9, banana : 4, orange : 8}
import time
start_time = time.time() # Code to check follows a, b = 1,2 c = a+ b # Code to check ends end_time = time.time() time_taken_in_micro = (end_time- start_time)*(10**6) print(" Time taken in micro_seconds: {0} ms").format(time_taken_in_micro)
from iteration_utilities import deepflatten # if you only have one depth nested_list, use this def flatten(l): return [item for sublist in l for item in sublist] l = [[1,2,3],[3]] print(flatten(l)) # [1, 2, 3, 3] # if you don t know how deep the list is nested l = [[1,2,3],[4,[5],[6,7]],[8,[9,[10]]]] print(list(deepflatten(l, depth=3))) # [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
import random
my_list = [ a , b , c , d , e ] num_samples = 2 samples = random.sample(my_list,num_samples) print(samples) # [ a , e ] this will have any 2 random values
import secrets # imports secure module. secure_random = secrets.SystemRandom() # creates a secure random object. my_list = [ a , b , c , d , e ] num_samples = 2 samples = secure_random.sample(my_list, num_samples) print(samples) # [ e , d ] this will have any 2 random values
num = 123456 # using map list_of_digits = list(map(int, str(num))) print(list_of_digits) # [1, 2, 3, 4, 5, 6] # using list comprehension list_of_digits = [int(x) for x in str(num)] print(list_of_digits) # [1, 2, 3, 4, 5, 6]
def unique(l):
if len(l)==len(set(l)): print("All elements are unique") else: print("List has duplicates") unique([1,2,3,4]) # All elements are unique unique([1,1,2,3]) # List has duplicates
從零開始詳細解說神經網路和深度學習
重點講解時序資料分析模型——迴圈神經網路RNN
從基礎到應用、從理論到實踐
公式齊全、程式碼豐富,使用熱門Python庫逐一實現
1. 梳理基礎數學知識和Python知識,為深入理解打基礎
2. 數學公式講解詳細,為讀懂大部頭開路
3. 相同程式碼通過TensorFlow和Keras分別實現,對比說明,更易理解
4. 以sin波為例講解迴圈神經網路的理論和實現,詳細介紹LSTM演算法
喜歡文章,點個在看
相關文章
- 在Python程式設計面試前需要學會的10個演算法(附程式碼)Python程式設計面試演算法
- 包教包會!7段程式碼帶你玩轉Python條件語句(附程式碼)Python
- Python程式設計會用到哪些軟體?Python基礎學習Python程式設計
- 5大Python程式設計師會用到的IDE和編輯器,你用過哪個?Python程式設計師IDE
- 30個python教你學會優雅的寫程式碼Python
- 20個Python random模組的程式碼示例Pythonrandom
- 前端必會的程式碼段前端
- 你可能會用到的一個路由介面卡路由
- 4款好用到哭的Kubernetes工具和框架框架
- 初學Java的5個階段,你在哪個階段?Java
- 即學即用的 30 段 Python 非常實用的程式碼Python
- CORNERSTONE | 好用到哭的專案管理工具專案管理
- 學Python到哪個機構好?都需要學什麼內容?Python
- 想要寫出好味道的程式碼,你需要養成這些好習慣!
- 學習Python需要什麼基礎?如何學好Python?Python
- Python機器學習會應用到哪些庫?Python入門學習Python機器學習
- Python練手程式碼段(2020.11.11)Python
- 不會寫程式碼的播音生不是個好運營?
- 這20個Docker Command,有幾個是你會的?Docker
- 30秒內便能學會的30個超實用Python程式碼片段Python
- Python程式設計需要用到什麼軟體?Python線下教程Python程式設計
- 用python寫小遊戲,沒有學過python的也會這個打程式碼Python遊戲
- Python好學嗎?精通Python需要多長時間?Python
- Python的十七個騷操作,你都學會了嗎?(上)Python
- 如何真正的學會,學好python,5分鐘?8個月?一輩子?Python
- 自述:javaWeb剛學時所需要的用到的jsJavaWebJS
- 學會網頁製作,web app開發,你需要掌握這3個程式語言網頁WebAPP
- 參加Python培訓到底需要學什麼?好程式設計師Python程式設計師
- 學習SSM階段使用到的jar包座標.SSMJAR
- 學習哪個程式語言呢?Python和C#哪個好學?PythonC#
- 零基礎如何學習好python爬蟲?分哪幾個階段?Python爬蟲
- 零基礎學習程式設計,Java、Python你會選擇哪個?程式設計JavaPython
- 好程式設計師Python培訓分享python中爬蟲常用到的正規表示式程式設計師Python爬蟲
- Python魔法:20個讓你程式設計事半功倍的奇淫技巧(建議收藏)Python程式設計
- 學Java需要用到的軟體快收藏!Java
- 一個學習Python的好連結Python
- 掌握一個事物時所需要學會的
- 【翻譯】使用這20個好的css技巧提升你的CSS技能CSS