5 odpowiedzi
+ 3
Iutsavsingh ( 1 ) The code is working. It is just that sys.stdin.readlines() takes the input but the list will only consist of one element. For example, my Inputs are: 2 a b c d a b c d 2 is the n which indicates the number of pairs. "a b" and "c d" are my two pairs. "a b c d" is assigned to "lines" But I tried to print the "lines" variable and I got ["a b c d"] which means that it is taking the input but the list will only consist of one element. Although this input will work or return True: 2 a b c d a This will return a=a. But remember that when using "membership in" in a dictionary, we are using its keys instead of its values. If you want to use the value then just use if x in dict.values():
14th Jan 2021, 3:53 PM
noteve
noteve - avatar
+ 3
( 2 ) If you want this input to work: 2 <--- no. of pairs a b <--- pair1 c d <--- pair2 a c <--- lines variable # Here we want to find if "a" is a key in phoneBook and if "c" is a key in phoneBook. Then your iteration or for loop should be like this: for i in lines[0]: // code - - - - - Comparison - - - - - - for x in lines: print(x) >> a c for x in lines[0]: print(x) >> a >> c
14th Jan 2021, 4:00 PM
noteve
noteve - avatar
+ 2
Can you clarify what sys.stdin.readlines() does? Cause I had already imported the sys module and print the "lines" variable but I got an empty list. Thanks.
14th Jan 2021, 3:43 PM
noteve
noteve - avatar
+ 2
《 Nicko12 》 It will use for taking input from the user also used for reading escape character
14th Jan 2021, 3:45 PM
Utsav Singh
Utsav Singh - avatar
+ 2
《 Nicko12 》 done! I was not used import sys in top
15th Jan 2021, 4:10 AM
Utsav Singh
Utsav Singh - avatar