Posts: 3
Threads: 1
Joined: Jan 2019
Jan-31-2019, 04:08 PM
(This post was last modified: Jan-31-2019, 04:16 PM by Larz60+.)
Hello everybody,
I have a question about the lists.
How can I go through a list and compare the contents of the list and if it is correct then instead of a 1 there should always be a 0
Thank you for your Help.
wordList = ['hi', 'hello', 'this', 'that', 'is', 'of']
for word in wordList:
print(word)
print() when expression is == "Hello" than it should be 1 other 0
Posts: 15
Threads: 4
Joined: Jan 2019
Jan-31-2019, 04:16 PM
(This post was last modified: Jan-31-2019, 04:17 PM by buran.)
hi Alexandro,
I think this could be right for you :
wordList = ['hi', 'hello', 'this', 'that', 'is', 'of']
for word in wordList:
if word == 'hello':
print (1)
else :
print (0)
Posts: 3
Threads: 1
Joined: Jan 2019
Jan-31-2019, 04:33 PM
(This post was last modified: Jan-31-2019, 04:38 PM by buran.)
Hello,
Thanks for the quick help
Please see the questions in the Output Area
wordList = ['hi', 'hello', 'this', 'that', 'is', 'of', 'cat']
for word in wordList:
if word == 'hello':
print (1)
elif word =='that':
print (0)
else :
print (0)
print (word)
output:
0
1
0
0 ???? Why That dont work"???
0
0
0
cat ??? Why that dont go????
Posts: 15
Threads: 4
Joined: Jan 2019
maybe I don't understand what you would like to obtain with you code
your code print "0" for the 4th "print" because you write that in your "print". if you want to print another value for "that", you just need to change
and for the last print, "cat" is the last value of "word" when your list is scanned
hope to help you
Posts: 3
Threads: 1
Joined: Jan 2019
(Jan-31-2019, 04:48 PM)Scorpio Wrote: maybe I don't understand what you would like to obtain with you code
your code print "0" for the 4th "print" because you write that in your "print". if you want to print another value for "that", you just need to change
and for the last print, "cat" is the last value of "word" when your list is scanned
hope to help you
Thak you for your Help,
My Question is.
How can I go through a list and I need for "this" and for "that" 1 statement
wordList = ['hi', 'hello', 'this', 'that', 'is', 'of', 'cat']
Posts: 1,950
Threads: 8
Joined: Jun 2018
(Jan-31-2019, 04:59 PM)Alexandro Wrote: How can I go through a list and I need for "this" and for "that" 1 statement
This is not very helpful. From that I personally can't understand what you want to accomplish. Please put some effort in defining your objective.
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Posts: 15
Threads: 4
Joined: Jan 2019
(Jan-31-2019, 05:05 PM)perfringo Wrote: (Jan-31-2019, 04:59 PM)Alexandro Wrote: How can I go through a list and I need for "this" and for "that" 1 statement This is not very helpful. From that I personally can't understand what you want to accomplish. Please put some effort in defining your objective.
I agree with perfringo, I m trying to understand what you need but I Cann't do it
let us know more details
|