I am interested to list all the cities of earth which end with the string "video", like "Montevideo"

  • 1
    $\begingroup$ Try Select[CityData[], StringMatchQ[CommonName[#], "*video"] &]. $\endgroup$ – J. M.'s technical difficulties Jul 27 '17 at 13:17
  • 1
    $\begingroup$ It takes infinite amount of time to calculate... Something is wrong with those operations... $\endgroup$ – Boti Jul 27 '17 at 13:47
  • $\begingroup$ Unfortunately, you are right that it can get slow, especially if your Internet connection is not very good. $\endgroup$ – J. M.'s technical difficulties Jul 28 '17 at 1:41

Get the world-wide cities database from http://download.maxmind.com/download/worldcities/worldcitiespop.txt.gz

Unzip. You should get almost 3.2 million cities.


Select[list,StringMatchQ[#[[2]],StringExpression[__,"video"] ]&]//TableForm

I've kept the first column, so you can see the country. The last columns contain the coordinates, in case you want to do some geo plots with that.

But that takes several seconds and leaves out solutions like "...vidéo" and "Monte Video" and "... Montevideo Chico", which the o/p is presumably interested in as well. The above takes "end with the string 'video'" literally. You're must faster not using M at all for this and get all 41 cases (not just 35, as above) with a one-liner in less than a second:

LC_CTYPE=iso-8859-1 grep video worldcitiespop.txt

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.