• Jul 24, 2024 •AustinLeath
0 likes • 3 views
from statistics import median, mean, mode def print_stats(array): print(array) print("median =", median(array)) print("mean =", mean(array)) print("mode =", mode(array)) print() print_stats([1, 2, 3, 3, 4]) print_stats([1, 2, 3, 3])
• Jun 16, 2024 •lagiath
0 likes • 1 view
print('hello, world')
• Oct 15, 2022 •CodeCatch
1 like • 2 views
my_list = ["blue", "red", "green"] #1- Using sort or srted directly or with specifc keys my_list.sort() #sorts alphabetically or in an ascending order for numeric data my_list = sorted(my_list, key=len) #sorts the list based on the length of the strings from shortest to longest. # You can use reverse=True to flip the order #2- Using locale and functools import locale from functools import cmp_to_key my_list = sorted(my_list, key=cmp_to_key(locale.strcoll))
• Sep 14, 2024 •rgannedo-6205
0 likes • 2 views
https://codecatch.net/post/06c9f5b7-1e00-40dc-b436-b8cccc4b69be
• Oct 7, 2022 •KETRICK
0 likes • 4 views
x[cat_var].isnull().sum().sort_values(ascending=False)
• Nov 19, 2022 •CodeCatch
0 likes • 0 views
# Given a number n, print all primes smaller than or equal to n. It is also given that n is a small number. # For example, if n is 10, the output should be “2, 3, 5, 7”. If n is 20, the output should be “2, 3, 5, 7, 11, 13, 17, 19”. # Python program to print all primes smaller than or equal to # n using Sieve of Eratosthenes def SieveOfEratosthenes(n): # Create a boolean array "prime[0..n]" and initialize # all entries it as true. A value in prime[i] will # finally be false if i is Not a prime, else true. prime = [True for i in range(n + 1)] p = 2 while (p * p <= n): # If prime[p] is not changed, then it is a prime if (prime[p] == True): # Update all multiples of p for i in range(p * 2, n + 1, p): prime[i] = False p += 1 prime[0]= False prime[1]= False # Print all prime numbers for p in range(n + 1): if prime[p]: print (p) # driver program if __name__=='__main__': n = 30 print("Following are the prime numbers smaller") print("than or equal to ", n) print("than or equal to ", n) SieveOfEratosthenes(n)