Square(n) Sum in Python
The challenge
Complete the square sum function so that it squares each number passed into it and then sums the results together.
For example, for [1, …
329 articles about python development, tools, and best practices
Complete the square sum function so that it squares each number passed into it and then sums the results together.
For example, for [1, …
We want an array, but not just any old array, an array with contents!
Write a function that produces an array with the numbers `` to N-1 …
The below Python code will create a connection to a MSSQLServer instance, and retrieve data from it back into a variable called tblResults.
# use …
Read Article →
Numbers ending with zeros are boring.
They might be fun in your world, but not here.
Get rid of them. Only the ending ones.
1450 -> …
Read Article →
When you have performance problems in your Python application, you can use a Profiler to help you.
Your first option is to run …
Read Article →Given a non-negative integer, 3 for example, return a string with a murmur: "1 sheep...2 sheep...3 sheep...". Input will …
If you have a CommandLine application (CLI) written in Python, you have a number of ways that you can take arguments from the user.
You could take the …
Read Article →Python provides the ability to create Translation Tables.
our_text = "This is an example of some text"
translation_table = …
Read Article →
Let’s take the following string:
numbers = "this 1 2 3 4 5 is not a 8 9 10"
How can we sum up all the numbers in this string? …
Read Article →Python’s itertools.permutations handles this in one line:
from itertools import permutations
perms = sorted([ …Let’s take the following sentence:
words = "These are some words"
We can use slices to reverse the order of the string:
print( …
Read Article →
Welcome to our comprehensive guide on how to python base64 encode a string in Python. …
The random module allows you to generate choices.
import random
print(random.choices([i for i in range(1000)], k=10))
This might give us back …
Read Article →Return the middle character of the word. If the word’s length is odd, return the middle character. If the word’s length is …
Read Article →If you have a string and want to create a Datetime object out of it in Python, then you can use the Datetime Parse Time method, as follows:
from …
Read Article →
Python ships with a multiprocessing module that allows your code to run functions in parallel by offloading calls to available processors.
In this …
Read Article →Given a string, you have to return a string in which each character (case-sensitive) is repeated once.
double_char("String") …
Read Article →
Complete the function that accepts a string parameter, and reverses each word in the string. All spaces in the string should be …
Read Article →Create a function with two arguments that will return an array of the first (n) multiples of (x).
Assume both the given number and the …
Read Article →Given a list of integers and a single sum value, return the first two values (parse from the left please) in order of appearance that …
Read Article →If you have a large list and want to create smaller lists of it, with a maximum amount of elements, then:
commands = [str(i) for i in range(100)] …
Read Article →
If you want to print out a list of all dates between 2 dates (a date range), then you can use the following script:
from datetime import date, …
Read Article →
If you want to append a Python dictionary to a Pandas DataFrame, you can do this:
# Create a new DataFrame
output = pd.DataFrame()
# Append the …
Read Article →
You can store secrets in AWS Secret Manager and reference their ARN in AWS Systems Secret Manager.
The below snippet allows you to specify the …
Read Article →