die Liste gegeben Unter der Annahme ist eine Liste von Strings. In diesem Fall benutzen Sie bitte diesen Code.
l1 = ["000000 = 0.0218354767535",
"000001 = 0.0218265654136",
"000002 = 0.0218184623573",
"000003 = 0.021811165579",
"000004 = 0.0218046731276",
"000005 = 0.0217989831063",
"000006 = 0.0217940936718",
"000007 = 0.0217900030345",
"000008 = 0.0217867094577",
"000009 = 0.0217842112574",
"000010 = 0.021782506802"]
for each_item in l1:
print each_item[-3:]
Modified Antwort nach Klärung
result_list = [] # This would store the end result with int
# The below list is the input list with floats
l1 = [0.0218354767535,
0.0218265654136,
0.0218184623573,
0.021811165579,
0.0218046731276,
0.0217989831063,
0.0217940936718,
0.0217900030345,
0.0217867094577,
0.0217842112574,
0.021782506802]
#For each float in the list, find the decimal part, convert to string, extract last 3, convert to int and append to result list
for each_item in l1:
result_list.append(int(str(each_item-int(each_item))[-3:]))
print result_list
Ausgabe
[535, 136, 573, 579, 276, 63, 718, 345, 577, 574, 802]
Diese Werteliste empfangen Strings sind, unser Verständnis korrekt ist? – pmaniyan
nein das sind Float-Werte, ich bekomme es vom Graph, das sind Werte von "x" aus Differentialgleichung erster Ordnung, ich habe 500000 Iteration und ich möchte letzten drei Ziffern aus jedem Element des Arrays auswählen. – faiz
Ich habe meine Antwort geändert, um die Eingabe als Liste von float zu nehmen und als Liste von ganzen Zahlen (die letzten 3 Ziffern von float) auszugeben. – pmaniyan