Python Forum
But why? Because of the for loop?
Thread Rating:
  • 1 Vote(s) - 1 Average
  • 1
  • 2
  • 3
  • 4
  • 5
But why? Because of the for loop?
#1
Hi everyone,
I am working on a program that decides if the content gets googled or if it searches for images. I filter the words and remove words that are not needed but there is a problem I can't figure out how to solve. If I input "search for pictures of Bitcoin" I get the output:
I will search for: pictures Bitcoin
I will search for pictures of: Bitcoin

Is it because of the for loop? I tried to remove words if they are in google so the loop will never be used but I didn't work:

Here is my code:
google_loop = 0
pictures_loop = 0


cut_words_google = ["for",  "online", "of", "me"]
cut_words_pictures = ["for", "online", "of", "me", "google", "search", "look", "online"]
google = ["google", "search", "look", "online"]
pictures = ["show", "images", "pictures", "photos"]
words = input()
test = words
 
for word in words.split(" "):
	if word in pictures and word not in google:
		words = ""
		pictures_loop = 1

	if word in google and word not in pictures:
		words = ""
		google_loop = 1

while google_loop == 1:
	for word in google:
		test = test.replace(word, "")
	for word in cut_words_google:
		test = test.replace(word, "")
		test = test.replace("  ", " ")
	print("I will search for: " + test)
	google_loop = 0
	test == ""
	words == ""

while pictures_loop == 1:
	for word in pictures:
		test = test.replace(word, "")
	for word in cut_words_pictures:
		test = test.replace(word, "")
		test = test.replace("  ", " ")
	print("I will search for pictures of: " + test)
	pictures_loop = 0
	test == ""
	words == ""
Reply


Messages In This Thread
But why? Because of the for loop? - by hello_its_me - Dec-30-2017, 12:47 PM
RE: But why? Because of the for loop? - by squenson - Dec-30-2017, 01:21 PM
RE: But why? Because of the for loop? - by squenson - Dec-30-2017, 05:16 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020