Отсеяв лишнее, оставив только дату. При этом, сохранить у test1 тип datatime
date1 = datetime.datetime.fromisoformat('2021-09-08 15:45:40.260000+00:00')
# datetime.datetime(2021, 9, 8, 15, 45, 40, 260000, tzinfo=datetime.timezone.utc)
date1.strftime('%Y-%m-%d')
# '2021-09-08'
date1.date()
# datetime.date(2021, 9, 8)
date1.date().isoformat()
# '2021-09-08'
datetime.datetime.combine(date1.date(), datetime.datetime.min.time())
# datetime.datetime(2021, 9, 8, 0, 0)
import math
a, alpha, x = 10, 10, 10
y1 = math.log(abs(x**3)) + math.tan(alpha)-pow(math.e, a*(x**2)+x)
print(y1)
# OverflowError: (34, 'Result too large')
import math
import decimal
decimal.getcontext().prec = 100
a, alpha, x = 10, 10, 10
y1 = decimal.Decimal(math.log(decimal.Decimal(abs(decimal.Decimal(x)**decimal.Decimal(3))))) \
+ decimal.Decimal(math.tan(decimal.Decimal(alpha))) \
- decimal.Decimal(pow(decimal.Decimal(math.e), decimal.Decimal(a)*(decimal.Decimal(x)**decimal.Decimal(2))+decimal.Decimal(x)))
print(y1)
# -4.339370400623091759291109148627508614055728677394889807059531826625028640984354352252576981241604834E+438
In [1]: import importlib
In [2]: requests.__version__
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-2-37d800a179a9> in <module>
----> 1 requests.__version__
NameError: name 'requests' is not defined
In [3]: requests = importlib.import_module('requests')
In [4]: requests.__version__
Out[4]: '2.22.0'
import pickle
# An arbitrary collection of objects supported by pickle.
data = {
'a': [1, 2.0, 3, 4+6j],
'b': ("character string", b"byte string"),
'c': {None, True, False}
}
with open('data.txt', 'wb') as f:
# Pickle the 'data' dictionary using the highest protocol available.
pickle.dump(data, f, pickle.HIGHEST_PROTOCOL)
import pickle
with open('data.txt', 'rb') as f:
# The protocol version used is detected automatically, so we do not
# have to specify it.
data = pickle.load(f)
print(data)
# {'a': [1, 2.0, 3, (4+6j)], 'b': ('character string', b'byte string'), 'c': {None, True, False}}
import re
text1 = '@0'
text2 = '0'
print(text1, text1.startswith('@'))
print(text2, text2.startswith('@'))
print(text1, bool(re.match('^@', text1)))
print(text2, bool(re.match('^@', text2)))
print(text1, text1[:1] == '@')
print(text2, text2[:1] == '@')
# @0 True
# 0 False
# @0 True
# 0 False
# @0 True
# 0 False
import csv, io, json
data = '''X Y
1 1
2 2
3 3
4 4
5 5'''
f = io.StringIO(data)
reader = csv.DictReader(f, delimiter=' ')
json.dumps(list(reader))
# '[{"X": "1", "Y": "1"}, {"X": "2", "Y": "2"}, {"X": "3", "Y": "3"}, {"X": "4", "Y": "4"}, {"X": "5", "Y": "5"}]'
import requests
r = requests.get("http://search.maps.sputnik.ru/search/addr?format=json&lat&q=Песочная+аллея,+дом+1")
print(r.json()['result']['address'][0]['features'][0]['geometry']['geometries'][0]['coordinates'])
# [37.674698, 55.79341]
coordinates = []
def search_key(data, key):
if isinstance(data, list):
for x in data:
search_key(x, key)
if isinstance(data, dict):
for x in data.keys():
if x == key:
coordinates.append(data[x])
else:
search_key(data[x], key)
search_key(r.json(), 'coordinates')
print(coordinates)
# [[37.674698, 55.79341]]
data1 = {'key': '1', 'phone': '2'}
data2 = {'key': '3', 'telephone': '4'}
data3 = {'key': '5', 'telePhone': '6'}
data4 = {'key': '7', 'PHONE': '8'}
data5 = {'key': '9', 'Телефон': '10'}
PATTERNS = ['phone', 'телефон'] # тут перечислить подстроки
getphone = lambda data:next(filter(lambda x: any([y in x.lower() for y in PATTERNS]), data.keys()))
print(data1[getphone(data1)])
print(data2[getphone(data2)])
print(data3[getphone(data3)])
print(data4[getphone(data4)])
print(data5[getphone(data5)])
# 2
# 4
# 6
# 8
# 10