Loading...
More Python Posts
def byte_size(s):return len(s.encode('utf-8'))byte_size('😀') # 4byte_size('Hello World') # 11
# Listlst = [1, 2, 3, 'Alice', 'Alice']# One-Linerindices = [i for i in range(len(lst)) if lst[i]=='Alice']# Resultprint(indices)# [3, 4]
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])
# Function to multiply two matricesdef multiply_matrices(matrix1, matrix2):# Check if the matrices can be multipliedif len(matrix1[0]) != len(matrix2):print("Error: The number of columns in the first matrix must be equal to the number of rows in the second matrix.")return None# Create the result matrix filled with zerosresult = [[0 for _ in range(len(matrix2[0]))] for _ in range(len(matrix1))]# Perform matrix multiplicationfor i in range(len(matrix1)):for j in range(len(matrix2[0])):for k in range(len(matrix2)):result[i][j] += matrix1[i][k] * matrix2[k][j]return result# Example matricesmatrix1 = [[1, 2, 3],[4, 5, 6],[7, 8, 9]]matrix2 = [[10, 11],[12, 13],[14, 15]]# Multiply the matricesresult_matrix = multiply_matrices(matrix1, matrix2)# Display the resultif result_matrix is not None:print("Result:")for row in result_matrix:print(row)
import osimport sysimport argparseimport jsonimport csvimport getpassimport stringimport randomimport refrom datetime import datetimeimport ldapimport requestsfrom requests.packages.urllib3.exceptions import InsecureRequestWarningrequests.packages.urllib3.disable_warnings(InsecureRequestWarning)from requests.auth import HTTPBasicAuthimport validatorsdef create_guac_connection(BASE_URL, auth_token, ldap_group, computer, guac_group_id):'''creates a guac connection'''json_header = {'Accept': 'application/json'}query_parm_payload = { 'token': auth_token }payload_data = {"parentIdentifier":guac_group_id,"name":computer,"protocol":"vnc","parameters":{"port":"5900","read-only":"","swap-red-blue":"","cursor":"","color-depth":"","clipboard-encoding":"","disable-copy":"","disable-paste":"","dest-port":"","recording-exclude-output":"","recording-exclude-mouse":"","recording-include-keys":"","create-recording-path":"","enable-sftp":"true","sftp-port":"","sftp-server-alive-interval":"","enable-audio":"","audio-servername":"","sftp-directory":"","sftp-root-directory":"","sftp-passphrase":"","sftp-private-key":"","sftp-username":"","sftp-password":"","sftp-host-key":"","sftp-hostname":"","recording-name":"","recording-path":"","dest-host":"","password":"asdasd","username":"asdasd","hostname":"nt72310.cvad.unt.edu"},"attributes":{"max-connections":"","max-connections-per-user":"1","weight":"","failover-only":"","guacd-port":"","guacd-encryption":"","guacd-hostname":""}}CREATE_CONNECTION_URL = BASE_URL + "/api/session/data/mysql/connections"create_connection_request = requests.post(CREATE_CONNECTION_URL, headers=json_header, params=query_parm_payload, data=payload_data, verify=False)create_connection_result = create_connection_request.status_codeif create_connection_result == "200":print("Successfully created computer: " + computer)else:print(create_connection_request.json())return create_connection_result
# Python code to demonstrate# method to remove i'th character# Naive Method# Initializing Stringtest_str = "CodeCatch"# Printing original stringprint ("The original string is : " + test_str)# Removing char at pos 3# using loopnew_str = ""for i in range(len(test_str)):if i != 2:new_str = new_str + test_str[i]# Printing string after removalprint ("The string after removal of i'th character : " + new_str)