1
$\begingroup$

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

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

1 Answer 1

3
$\begingroup$

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.

list=Import[ToFileName[{$HomeDirectory,"Downloads"},"worldcitiespop.txt"],"CSV"][[All,{1,3}]];

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

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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