0

I have a file has the cities names and information such as names, coordinates of the city and population of the city

Youngstown, OH[4110,8065]115436
Yankton, SD[4288,9739]12011
966
Yakima, WA[4660,12051]49826
1513 2410
Worcester, MA[4227,7180]161799
2964 1520 604
Wisconsin Dells, WI[4363,8977]2521
1149 1817 481 595

How can I create a function to to take the city name and return a list containing the latitude and longtitude of the given city?

I am so desperate now,, Any help will be much appreciated...thanks guys....

fin = open ("miles.dat","r")
def getCoordinates cities = []
for line in fin:
cities.append(line.rstrip())
for word in line:
print line.split()

that's what I tried now....how could I get the coordinates of the city by calling the names of the city and how can i return the word of each line but not letters?

Edited by braybray: to explain

2
Contributors
1
Reply
2
Views
5 Years
Discussion Span
Last Post by woooee
0

If you want to use split (and how do you post code that is not indented, like the following. If we have to add 4 extra space to every freaking line of code that we post, I'm finding a new forum)

test_line="Youngstown, OH[4110,8065]115436"

# your way
for item in test_line.split():
    print item
print


# a better way
test_list=test_line.split("[")
for item in test_list:
    print item
print test_list[1].split("]")
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.