Planes in the eet boeing 777 b777 wingspan 648 m

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:   Data structures such as sets and dic2onaries that ignore order are called unordered (lists, on the other hand are ordered!) 26 CMPUT174  ­ ­ Dic2onaries Applica$on: coun$ng • Oaen we need to calculate the frequency with which certain things happen. We do this by coun2ng • Example: es2ma2ng 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 2mes   “is” occurs 3 2mes   “a” occurs 3 2mes CMPUT174  ­ ­ Dic2onaries 27 9 13 ­10 ­29 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 punctua2on   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 dic2onary 28 CMPUT174  ­ ­ Dic2onaries Applica$on: coun$ng • Assuming the words are “cleaned”, we count each word using a dic2onary (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 29 CMPUT174  ­ ­ Dic2onaries Using dic$onaries to keep “records” • Back to our planes example… suppose we want to keep detailed informa2on 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  ­ ­ Dic2onaries Airbus 330 (A330): •  Wingspan: 60.3 (m) •  Length: 63.6 (m) •  Seats: 37 (b), 228 (e) •  Speed: 869 (Km/h) •  Range: 10560 (Km) •  Altitude:...
View Full Document

Ask a homework question - tutors are online