ماه: اکتبر 2019

minimum_swaps

def minimum_swaps(ratings): cr = ratings.copy() for i,x in enumerate(ratings): max_x = max(ratings) idx = ratings.index(max_x) #print(i, idx, max_x, cr) if 1 : #idx+i<=len(cr): print(max_x,i,idx,cr,ratings) cr[i]=max_x cr[idx+i]=ratings[0] ratings = cr[i::] del ratings[0] print(ratings) print(minimum_swaps([8,3,9,1,5]))

کد پایتون چاپ مثلث ستاره

st = ‘*’ blk = ‘ ‘ for i in range(10): str_out = blk*(9-i)+st*i+st*i+blk*(9-i) print(str_out)            **        ****       ******      ********     **********    ************   **************  **************** ******************

Bubble Sort Algorithm in Python

import string import os import random def bubbleSort(arr): L = len(arr)-1 for j in range(L): for i in range(L): if arr[i]>=arr[i+1]: ari = arr[i] ari1 = arr[i+1] arr[i]=ari1 arr[i+1]=ari print(arr) return arr ar3 = [50,6,90,800,4,56,33,2100,400] print(bubbleSort(ar3))