![]() In this program, the textfile is read in one place, it is processed to remove (some) punctuation in another place, and split into words in two other places. New York) work correctly if both cities are in the text? Can you test it to make sure? What about cities with more than two words (e.g., Rio de Janeiro).įunctions can also help you keep related code together. For example, does the code to check if a one word city (e.g. Separate functions lets you test portions of your program to make sure they work as intended. A rule of thumb is that a function should fit on your screen so you can see all of it at once. To help structure and manage the program, try breaking it up into several functions that each do one thing. That makes it hard to understand and reason about. ![]() So when someone (or you) reading your code sees the variable x, they must look around to see what x is this time. In your code, sometimes x is a word in the text file, other times it is a two word city, any city, a typo, or a text line in the final output. ![]() 'temp', 'stupid' probably aren't meaningful.Īnd try to be consistent about a variables represent. That doesn't mean they have to be long names, depending on the context i,j,k or x,y,z can be meaningful names. Or better yet use a with statement to automatically close the file at the end of the code block (the indented part) with open('TEXT.txt','r') as txtfile: Here are some general comments: Close filesĬlose files when you are done with them. Print('\n You have entered the following cities:') #determining which country they mean when they mentioned repeating cities #finding out what cities repeat and adding all their information to repeat #removing one city words identified from two worded cities (York vs New #finding out where the talked about cities are Repeatinfo = #contain all infor about repeating cities ![]() Templist = #holds the cities(state and country) info of the placesĪll_cities = #holds all the cities mentioned, used to check for #assigned certain parts of data set to variable import pandas as pdĭataset = pd.read_csv('world-cities.csv') I am trying not to use imports like geotext, and instead focus more on finding the most logically efficient way to program. So this was a bootleg method to get rid of them. I had a problem with words such as 'and' showing up as typos. I used it to compare to 'TEXT.txt' to remove common words. 'usa.txt' contains common words in the english language. 'TEXT.txt' is a file that contains the sentences that I will be analyzing for cities. 'world-cities.csv' is a file that contains a lot of cities in the world. Please let me know what concepts I can use to further simplify my code.įile Explanations: I am using a text called 'world-cities.csv', 'TEXT.txt' and 'usa.txt'. ![]() Problem: My code has been working pretty well, but I feel it can be significantly simplified. For example if they type 'Dalls' instead of 'Dallas' I need to provide the user options such as 'Do you mean Dallas instead of Dalls'. In addition if there is a slight typo, I ask the user if they meant a certain city instead. Requirements: If a mentioned city is in two or more countries, I ask the user to mention which city they are talking about. I am suppose to identify the cities mentioned and print their state and country. For this Code, I am provided a text file that contain several cities. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |