Moshe left Pharaoh and entreated Hashem [to remove the locust] (Shemos 10:18). Where would Moshe pray to Hashem to stop a plague? Somewhere outside the city, as the verse in last week’s parsha says: וַיֹּאמֶר אֵלָיו משֶה כְּצֵאתִי אֶת־הָעִיר אֶפְּרֹּשׂ אֶת־כַפַי אֶל ה‘ - And Moshe said to him, "When I leave the city, I will lift my hands to Hashem...” (Shemos 9:29). And Rashi explains why Moshe needed to leave the city: “Within the city he did not pray, because it was full of idols.”
Interestingly, this is reflected in halacha nowadays as well! Whenever possible, one should not pray in a non-Jewish inn that has idolatrous items there (see O.C. 94:8, Rama and Mishna Berura 94:29 & 94:30). The Mishna Berura (94:29) explains that since our prayers are words of קדושה (sanctity), one should not pray in a place that’s filled with idols - i.e., things that counter קדושה.
A fundamental lesson is learned from here: Tefilla needs to come from a place of purity. And if the outer place where a Jew offers his tefilla needs to be pure, then, certainly, the inner place from where his tefilla emerges, namely, his heart and lips need to be pure as well. [If you feel that you have spoken inappropriate words (such as loshon horah, deceit, lye, and hurtful words), do teshuva before you daven. The Chofetz Chaim teaches that a way to keep impurity from entering one’s heart is by not transgressing the sin of sinas chinam (Kuntres Ahavas Yisroel, ch.1). Hence, one of the “items” on the list to check for before you step into Shemoneh Esrei is the presence of Ahavas Yisroel towards every Jew in your heart.]