How Do You Write a Python Program without the import Statement That Palindromically Tests a String in Four Lines of Code?

Problem scenario
You want to avoid importing any modules in Python. You want to have a way to test if a string is a palindrome is four lines of code. What do you do?

Solution

def is_palindrome_pythonic(s):
return all(a == b for a, b, in zip(
map(str.lower, filter(str.isalnum, s)),
map(str.lower, filter(str.isalnum, reversed(s)))))

# The above four lines of code were taken from page 78 of Elements of Programming Interviews in Python. …

How Do You Use Python to Retrieve Information about Bitcoin Transactions?

Problem scenario
You want to use Python to get data from BTC transactions. You do not want to use “import requests”. What do you do?

Solution
Prerequisite

This assumes you have installed the Bitcoin pypi package: pip install bitcoin
If you need assistance installing pip, see this posting for Ubuntu or this posting for a Red Hat derivative.

How Do You Use Nomics to a Retrieve Cryptocurrency Prices?

Problem scenario
You want to use Nomics to retrieve cryptocurrency prices. What do you do?

Prerequisite
Get an API key. It is free here: https://p.nomics.com/pricing#free-plan
(You do not need to provided credit card information to obtain one.)

Procedures
Run this Python program but replace YOUR_KEY_HERE with the key:

import requests
resp = requests.get(“https://api.nomics.com/v1/prices?key=YOUR_KEY_HERE&format=json”)
for item in resp.json():
if item[’currency’] in [”BTC”, …

How Do You Retrieve Cryptocurrency Data for One Day in the Past Using Python?

Problem scenario
You want to find the historic data for a given cryptocurrency using Python. You want to print out the low, high, open and close prices on a specific day. How do you get data for one specific date?

Solution

Prerequisite
This assumes you have installed pandas: pip install pandas

Procedures
Run this program:

“””
Usage instructions: Change the “2016-12-25” the value (assigned to “date_to_see”) to the day you want to view. …

How Do You Print the Current Price of Bitcoin with Python without Installing New Packages?

Problem scenario
You do not want to install new Python modules. How do you use Python to print out the latest price of Bitcoin?

Solution
Run this program:

import requests
resp = requests.get(“https://api.coindesk.com/v1/bpi/currentprice/USD.json”)
print(resp.json()[’bpi’])

Here is a modified version of the program:

import requests
resp = requests.get(“https://api.coindesk.com/v1/bpi/currentprice/USD.json”)
print(resp.json()[’bpi’][’USD’][’rate’])

If you want to receive free cryptocurrency by just learning more,

What is the Difference between global and nonlocal in Python?

Question
It seems like “global” and “nonlocal” would be the same thing. How are these keywords different in Python?

Answer
Variables inside a function are local by default; variables outside of functions are global by default. (This was taken from https://www.programiz.com/python-programming/global-keyword.) This answer/article addresses the “LEGB lexical scoping rule” (taken from page 872 of Learning Python).

What Does a Colon Mean in Python when You See Something Like This “new_var = a[i:i + counter]”?

Question
You are not familiar with this example of a colon. It appears to be an assignment of a value to itself. You have seen Python function signatures with colons to explain the data type. You have seen colons to signify an if conditional or a for loop. You are not sure what this line of code does:

new_var = a[i:i + counter]

What does this type of colon syntax mean?

How Do You Use Python to Find The Latest Prices of Bitcoin, Ethereum, Litecoin and Ripple?

Problem scenario
You want to use Python to calculate the latest price of various cryptocurrencies. What should you do?

Solution
Prerequisite

This assumes you have installed pip.

Procedures
Install the Python package cryptocompare: pip install cryptocompare

Run this program:

import cryptocompare

print(cryptocompare.get_price(‘BTC’, ‘USD’))
print(cryptocompare.get_price(‘BTC’, ‘USD’))
print(cryptocompare.get_price(‘ETH’, ‘USD’))
print(cryptocompare.get_price(‘LTC’, ‘USD’))
print(cryptocompare.get_price(‘XRP’, …

How Do You Write a Flask Program to Accept a Parameter in the URL?

Problem scenario
You want to pass a variable via a URL to a Python program. You want to use Flask for this. What do you do?

Solution
Prerequisite

Install Flask. If you need assistance, see this posting if you are using a CentOS/RHEL/Fedora server or this posting if you are using a Debian/Ubuntu server.

Procedures
This is a multi-route Flask program.