Informatiker Board (http://www.informatikerboard.de/board/index.php)
- Themengebiete (http://www.informatikerboard.de/board/board.php?boardid=1)
-- Praktische Informatik (http://www.informatikerboard.de/board/board.php?boardid=6)
--- Python Listen vs Tuple (http://www.informatikerboard.de/board/thread.php?threadid=3852)


Geschrieben von Dr.Java am 01.02.2018 um 16:17:

  Python Listen vs Tuple

Hallo.Ich hab erneut ein Problem mit Python. Diesmal geht es um das timeit modul.
Ich soll mithilfe des Moduls untersuchen ob die Zeit auf einen Listenzugriff x=lst(k) langsamer ist als auf einen Tuplezugriff x=tpl(k).

Das ist mein Ansatz bisher,wobei die main hab ich schon so vorgegeben gehabt .

def ltp():
global x



if __name__ == '__main__':

import timeit

repeat = 5
number = 1000
unit = "usec"
unittosec = {"usec": 1e6, "msec": 1000, "sec": 1}

for fct_name in ["ltp"]:
res = timeit.repeat(
"%s()" % fct_name,
setup="from __main__ import %s" % fct_name,
repeat=repeat, number=number)
print("%s: %d loops, best of %d: %.3g %s per loop" %
(fct_name,
number, repeat,
min(res) / number * unittosec[unit],
unit))

Ich habe dann überlegt das man zunächst eine Funktion für die Listen und Tuple erstellen muss.Aber irgendwie stehe ich damit ein wenig auf dem Schlauch.
Kann mir vielleicht jemanden einen Tipp geben?

Danke im voraus und lg


Forensoftware: Burning Board, entwickelt von WoltLab GmbH