(c) 2023 Technische Hochschule Augsburg - Fakultät für Informatik - Prof.Dr.Nik Klever - Impressum
from array import array
a = array("H", [1,2,3,4])
a
array('H', [1, 2, 3, 4])
with open("binär.bin","wb") as f:
a.tofile(f)
!hexdump binär.bin -C
00000000 01 00 02 00 03 00 04 00 |........| 00000008
a = array("H", range(65,67))
a
array('H', [65, 66])
with open("binär.bin","wb") as f:
a.tofile(f)
!hexdump binär.bin -C
00000000 41 00 42 00 |A.B.| 00000004
ord("B")
66
hex(ord("B"))
'0x42'
from collections import deque
d = deque([1,2,3])
print("Warteschlange:",d)
Warteschlange: deque([1, 2, 3])
n = 4
d.append(n)
print("Warteschlange:",d)
Warteschlange: deque([1, 2, 3, 4])
b = d.popleft()
b
1
print("Warteschlange:",d)
Warteschlange: deque([2, 3, 4])
from collections import OrderedDict
d = {"Banane": 3, "Zitrone": 12, "Kiwi": 5, "Orange":15}
od = OrderedDict(d)
od
OrderedDict([('Kiwi', 5), ('Orange', 15), ('Banane', 3), ('Zitrone', 12)])
import bisect
tupelliste = [(1,"Apfel"),(5,"Banane"),(8,"Zitrone")]
bisect.insort(tupelliste,(3,"Birne"))
tupelliste
[(1, 'Apfel'), (3, 'Birne'), (5, 'Banane'), (8, 'Zitrone')]
heap[k] <= heap[2*k+1] and heap[k] <= heap[2*k+2] # für alle k >= 0; heap[x] = unendlich, wenn x > len(heap)
from heapq import heapify, heappop, heappush
def testheap(data):
for i in range(len(data)):
compare = [True, True]
for j in 0,1:
if 2*i+j+1 < len(data):
compare[j] = data[i] <= data[2*i+j+1]
if not (compare[0] and compare[1]):
print("data is not a heap")
break
else:
print("data is a heap")
data = [1,3,5,7,9,2,4,6,8,0]
print(data)
testheap(data)
[1, 3, 5, 7, 9, 2, 4, 6, 8, 0] data is not a heap
heapify(data)
print(data)
testheap(data)
[0, 1, 2, 6, 3, 5, 4, 7, 8, 9] data is a heap
from decimal import *
round(Decimal("0.70")*Decimal("1.05"), 2)
Decimal('0.74')
round(0.70*1.05,2)
0.73
Decimal("1.00") % Decimal(".10")
Decimal('0.00')
1.0 % 0.1
0.09999999999999995
sum([Decimal("0.1")]*10) == Decimal("1.0")
True
sum([0.1]*10) == 1.0
False
sum([0.1]*10) - 1.0
-1.1102230246251565e-16
getcontext()
Context(prec=28, rounding=ROUND_HALF_EVEN, Emin=-999999, Emax=999999, capitals=1, clamp=0, flags=[Inexact, Rounded], traps=[InvalidOperation, DivisionByZero, Overflow])
getcontext().prec=36
Decimal(1) / Decimal(7)
Decimal('0.142857142857142857142857142857142857')