Create Python dictionary from text file -
how 1 create dictionary text file?
the test file consists of:
von neumann architecture describes general framework, or structure, computer's hardware, programming, , data should follow. although other structures computing have been devised , implemented, vast majority of computers in use today operate according von neumann architecture.the von neumann in von neumann architecture refers hungarian-american mathematician john von neumann (1903-1957). von neumann interested in access fastest computers available (of there few) during world war ii in order perform complex computations variety of war-related problems. in 1944, von neumann became consultant eniac (electronic numerical integrator , computer) project, upon completion in 1945 became world's first general purpose, electronic computer. before eniac's completion, von neumann , several members of team constructing eniac proposed building more advanced computer, become known edvac (electronic discrete variable automatic computer). in 1945 von neumann wrote landmark paper entitled first draft of report on edvac, encapsulated ideas concerning fundamental structure computer should follow. report, von neumann intended seen limited group of associates, nevertheless became disseminated , had immediate impact on computer development in united states , abroad.von neumann followed on first report producing 2 more papers coauthored colleagues eniac team. emerged these 3 papers overall structure, or architecture, by-and-large followed day vast majority of electronic, digital computers. von neumann envisioned structure of computer system being composed of following components: (1) central arithmetic unit, today called arithmetic-logic unit (alu). unit performs computer's computational , logical functions; (2) memory; more specifically, computer's main, or fast, memory, such random access memory (ram); (3) control unit directs other components of computer perform actions, such directing fetching of data or instructions memory processed alu; , (4) man-machine interfaces; i.e., input , output devices, such keyboard input , display monitor output. of course, computer technology has developed extensively since von neumann's time. instance, due integrated circuitry , miniaturization alu , control unit have been integrated onto same microprocessor chip, becoming integrated part of computer's central processing unit (cpu).the noteworthy concept contained in von neumann's first report of stored-program principle. principle holds data, instructions used manipulate data, should stored in same memory area of computer. idea deviated structure of previous computers. example, eniac's numeric data stored in vacuum tube memory, while instructions directed processing of data provided hardware settings. say, before each new computation eniac, operator set various dials, connected , disconnected various electric plugs, , forth. particular hardware settings represented eniac's programming. seemed obvious von neumann (as did several other people working on eniac project) have flexible, general-purpose computer meant stored program principle should implemented.one ramification of storing data , programming in same general area of computer's main memory need distinguish between two. contents of typical computer's main memory seen computer series of zeroes , ones (i.e., binary digits, or bits). computer needs direction in order determine whether particular block of information data or instructions. von neumann's control unit mechanism used make data-versus-instruction determination. when control unit initiates call instruction fetched processing, unit called program counter points instruction's location in memory (i.e., address in memory). instruction fetched execution processor. address in memory of data required provided instruction itself. during fetching , execution of instruction, program counter incremented next instruction can found , executed. process sequential, meaning instructions executed in ordered, sequential fashion, 1 instruction @ time. serial execution of instructions hallmark of von neumann computer architecture. in contrast parallel processing architectures in multiple instructions executed in tandem. true parallel processing computer considered non-von neumann architecture machine.to summarize main characteristics of von neumann architecture, noted that, first of all, such computer composed of distinct components, alu, control unit, input/output devices, , single memory unit storing both data , instructions (i.e., stored-program principle). secondly, instructions carried out sequentially, 1 instruction @ time. von neumann himself recognized, sequential execution of programming imposes sort of speed limit on program execution since 1 instruction @ time can handled computer's processor. computer pioneer john backus called von neumann bottleneck. bottleneck can manifest when computer's cpu processes @ rate faster information can delivered main memory. there have been plethora of techniques devised make of sequential nature von neumann architecture places on computers reducing information bottlenecks. development of faster processors has meant programs executed more quickly. processing speed has been increased modifying memory side of equation, in case of cache memory (which provides way of transferring information main memory smaller, faster memory device). other techniques include wider data buses carry information more between memory , cpu; reduction of wait states (i.e., reduction of time cpu required suspend processing while waiting information auxiliary storage); , many other speed-enhancing strategies. must pointed out, however, despite these advances , enhancements 1 still left fundamental von neumann architecture, followed in overwhelming majority of computers in use today. i need count unique words
print(len(set(w.lower() w in open('von_neumann.txt').read().split()))) and create dictionary in keys individual words found in file , values number of times each word appears in text.
i'm using python 3.3.2.
you can use collections.counter():
from collections import counter open('test.txt', 'rb') f: counter = counter() line in f: counter.update(line.split()) print counter prints:
counter({'the': 66, 'of': 38, 'a': 29, 'to': 24, 'and': 23, ... })
Comments
Post a Comment