Loading...
More Python Posts
# Python program for implementation of Bogo Sortimport random# Sorts array a[0..n-1] using Bogo sortdef bogoSort(a):n = len(a)while (is_sorted(a)== False):shuffle(a)# To check if array is sorted or notdef is_sorted(a):n = len(a)for i in range(0, n-1):if (a[i] > a[i+1] ):return Falsereturn True# To generate permuatation of the arraydef shuffle(a):n = len(a)for i in range (0,n):r = random.randint(0,n-1)a[i], a[r] = a[r], a[i]# Driver code to test abovea = [3, 2, 4, 1, 0, 5]bogoSort(a)print("Sorted array :")for i in range(len(a)):print ("%d" %a[i]),
list_1 = [1,2,3,4,5,6,7,8,9]cubed = map(lambda x: pow(x,3), list_1)print(list(cubed))#Results#[1, 8, 27, 64, 125, 216, 343, 512, 729]
print('hello, world')
def check_prop(fn, prop):return lambda obj: fn(obj[prop])check_age = check_prop(lambda x: x >= 18, 'age')user = {'name': 'Mark', 'age': 18}check_age(user) # True
import random# Define the ranks, suits, and create a deckranks = ['Ace', '2', '3', '4', '5', '6', '7', '8', '9', '10', 'Jack', 'Queen', 'King']suits = ['Hearts', 'Diamonds', 'Clubs', 'Spades']deck = [(rank, suit) for rank in ranks for suit in suits]# Shuffle the deckrandom.shuffle(deck)# Display the shuffled deckfor card in deck:print(card[0], "of", card[1])
primes=[]products=[]def prime(num):if num > 1:for i in range(2,num):if (num % i) == 0:return Falseelse:primes.append(num)return Truefor n in range(30,1000):if len(primes) >= 20:break;else:prime(n)for previous, current in zip(primes[::2], primes[1::2]):products.append(previous * current)print (products)