## key of minimum value

0 likes • Nov 19, 2022
Python

## More Python Posts

```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]```
```import anytree as atimport random as rm
# Generate a tree with node_count many nodes. Each has a number key that shows when it was made and a randomly selected color, red or white.def random_tree(node_count):        # Generates the list of nodes    nodes = []    for i in range(node_count):        test = rm.randint(1,2)        if test == 1:            nodes.append(at.Node(str(i),color="white"))        else:            nodes.append(at.Node(str(i),color="red"))        #Creates the various main branches    for i in range(node_count):        for j in range(i, len(nodes)):            test = rm.randint(1,len(nodes))            if test == 1 and nodes[j].parent == None and (not nodes[i] == nodes[j]):                nodes[j].parent = nodes[i]        #Collects all the main branches into a single tree with the first node being the root    for i in range(1, node_count):        if nodes[i].parent == None and (not nodes[i] == nodes[0]):            nodes[i].parent = nodes[0]
return nodes[0]```

### Bogo Sort

CodeCatch
0 likes • Nov 19, 2022
Python
```# 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 False	return 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]),```
```# question3.pyfrom itertools import productV='âˆ€'E='âˆƒ'
def tt(f,n) :  xss=product((0,1),repeat=n)  print('function:',f.__name__)  for xs in xss : print(*xs,':',int(f(*xs)))  print('')
# this is the logic for part A (p\/q\/r) /\ (p\/q\/~r) /\ (p\/~q\/r) /\ (p\/~q\/~r) /\ (~p\/q\/r) /\ (~p\/q\/~r) /\ (~p\/~q\/r) /\ (~p\/~q\/~r)
def parta(p,q,r) :    a=(p or q or r) and (p or q or not r) and (p or not q or r)and (p or not q or  not r)  b=(not p or q or r ) and (not p or q or not r) and (not p or not q or r) and (not p or not q or not r)  c= a and b  return c
def partb(p,q,r) :  a=(p or q and r) and (p or not q or not r) and (p or not q or not  r)and (p or q or  not r)  b=(not p or q or r ) and (not p or q or not r) and (not p or not q or r) and (not p or not q or not r)  c= a and b  return c
print("part A:")tt(parta,3)
print("part B:")tt(partb,3)```
`#Loop back to this point once code finishesloop = 1while (loop < 10):#All the questions that the program asks the user    noun = input("Choose a noun: ")    p_noun = input("Choose a plural noun: ")    noun2 = input("Choose a noun: ")    place = input("Name a place: ")    adjective = input("Choose an adjective (Describing word): ")    noun3 = input("Choose a noun: ")#Displays the story based on the users input    print ("------------------------------------------")    print ("Be kind to your",noun,"- footed", p_noun)    print ("For a duck may be somebody's", noun2,",")    print ("Be kind to your",p_noun,"in",place)    print ("Where the weather is always",adjective,".")    print ()    print ("You may think that is this the",noun3,",")    print ("Well it is.")    print ("------------------------------------------")#Loop back to "loop = 1"    loop = loop + 1`
```# Python program to reverse a linked list# Time Complexity : O(n)# Space Complexity : O(n) as 'next'#variable is getting created in each loop.
# Node class

class Node:
# Constructor to initialize the node object	def __init__(self, data):		self.data = data		self.next = None

# Function to reverse the linked list	def reverse(self):		prev = None		current = self.head		while(current is not None):			next = current.next			current.next = prev			prev = current			current = next		self.head = prev
# Function to insert a new node at the beginning	def push(self, new_data):		new_node = Node(new_data)		new_node.next = self.head		self.head = new_node
# Utility function to print the linked LinkedList	def printList(self):		temp = self.head		while(temp):			print temp.data,			temp = temp.next

# Driver program to test above functionsllist = LinkedList()llist.push(20)llist.push(4)llist.push(15)llist.push(85)