2017-07-20 5 views
-1

Ich versuche, den Inhalt der Datei in ein Wörterbuch zu stellen. Obwohl die Datei selbst unverändert bleibt, ist das Wörterbuch, das ich am Ende bekomme, immer anders.Python 3.5.2-Wörterbuch wird bei jedem Ausdruck neu gemischt

with open('sorted.txt') as fin: 
    lines = fin.readlines() 
    words = {i.split(' - ')[0]:i.split(' - ')[1] for i in lines} 

    for i in words.keys(): 
     print(i, '-', words[i]) 

Einmal es ist so etwas wie dieses:

bawl - реветь, вопить 
by the by - кстати, к слову (cм. by the way) 
staple - cкоба, основная черта, главная часть 
staggering - ошеломляющий, неустойчивый 
trample - давить, топтать, подавлять 
enthrall - очаровывать, увлекать, захватывать 
elusive - неуловимый 
lay off - увольнять 
at the drop of a hat - Fig. immediately; instantly; on the slightest signal or urging. 
feasible - осуществимый, выполнимый 
wince - вздрогнуть, поморщиться 
wax poetic - Fig. to speak poetically. I hope you will pardon me if I wax poetic for a moment when I say that your lovely hands drift across the piano keys like swans on a lake. 
supple - мягкий, податливый 
willy-nilly - spontaneous 
itsy-bitsy - незначительный 
ramble - прогуливаться для удовольствия, бродить без цели 
get off on sth - тащиться по чему-л. 
bring out - выявлять, обнаруживать 
apples and oranges - сравнение несравнимых вещей или понятий 
backlash - агрессивная реакция 
eat sb out of house and home - есть чужую еду 
meek - кроткий, смиренный 
chuckle - посмеиваться, хихикать 
gibberish - неразборчивая речь, чушь 
evocative of - вызывающий воспоминания о чем-л. 
supplication - мольба 
fall apart (inf.) - расчувствоваться, испытывать эмоциональные проблемы 
fumble - шарить, нащупывать 
on an ad-hoc basis - as demand arises, по необходимости 
plod along 
stammer - запинаться 
exasperate - раздражать, изводить, выводить из себя 
conspicuous - бросающийся в глаза, заметный 
to walk on eggshells - прилагать большие усилия, чтобы не расстроить кого-л. 
go out with a bang - If someone or something goes out with a bang, they stop 
existing or doing something in an exciting way. 

Und noch genau die gleiche Liste, aber gemischt.

Was mache ich falsch?

+5

Mögliche Duplikate von [Python-Wörterbuch, wie Schlüssel/Werte in der gleichen Reihenfolge wie erklärt halten?] (Https://stackoverflow.com/questions/1867861/python-dictionary-how-to-keep-keys-values- in der gleichen Reihenfolge wie deklariert –

Antwort

-2

Werfen Sie einen Blick ein die Python-Handbuch:

https://docs.python.org/3.5/tutorial/datastructures.html

5,4. Sets

Python enthält auch einen Datentyp für Mengen. Ein Set ist eine ungeordnete Sammlung ohne doppelte Elemente. Zu den grundlegenden Anwendungen gehören das Testen von Mitgliedschaften und das Eliminieren doppelter Einträge. Set-Objekte unterstützen auch mathematische Operationen wie Vereinigung, Schnittpunkt, Differenz und symmetrische Differenz.

Sie können Wörterbuchschlüssel in Betracht ziehen.

Verwandte Themen