{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Informa on about the planes in the eet boeing 777 b777

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: nd dic-onaries that ignore order are called unordered (lists, on the other hand are ordered!) CMPUT174  ­ ­ Dic-onaries 26 Applica$on: coun$ng • Oaen we need to calculate the frequency with which certain things happen. We do this by coun-ng • Example: es-ma-ng the frequency of words in text "Rose is a rose is a rose is a rose.” Gertrude Stein, 1913 • The frequencies are:   “rose” occurs 4 -mes   “is” occurs 3 -mes   “a” occurs 3 -mes CMPUT174  ­ ­ Dic-onaries 27 Applica$on: coun$ng "Rose is a rose is a rose is a rose.” ? [‘rose’, ‘is’, ‘a’, ‘rose’, ‘is’, ‘a’, ‘rose’, ‘is’, ‘a’, ‘rose’] • Here is the design of a program to find word frequencies for any given text:   Step 1: split each line of text (using the split() method for strings)   Step 2: remove punctua-on   Step 3: convert all words to the same case (so we count Rose and rose together)   Step 4: count each cleaned ­up word using a dic-onary CMPUT174  ­ ­ Dic-onaries 28 Applica$on: coun$ng • Assuming the words are “cleaned”, we count each word using a dic-onary (keys are words, values are counts) check if the word has been seen before increment the count for words previously seen start the count for words seen for the first time CMPUT174  ­ ­ Dic-onaries 29 Using dic$onaries to keep “records” • Back to our planes example… suppose we want to keep detailed informa-on about the planes in the fleet Boeing 777 (B777): •  Wingspan: 64.8 (m) •  Length: 73.9 (m) •  Seats: 42 (b), 307 (e) •  Range: 14594 (Km) •  Speed: 896 (Km/h) •  Altitude: 35000 (ft) •  Cargo: 24000 (Kg) CMPUT174  ­ ­ Dic-onaries Airbus 330 (A330): •  Wingspan: 60.3 (m) •  Length: 63.6 (m) •  Seats: 37 (b), 228 (e) •  Speed: 869 (Km/h) •  Range: 10560 (Km) •  Altitude: 37000 (ft) •  Cargo: 13900 (Kg)...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online