我正在开发一个程序的伪代码,该程序允许在listofitems中找到一个listitem。伪代码对我来说仍然是一个外国概念,我可能会发现这个错误的110%......所以这就是伪代码......
listofitems= [1, 2, 'a']
define function findItem(object1, object2, object3):
listItem = raw_input("Find this item in the list: ")
for each item in findItem:
if listItem = object1 in findItem or listItem = object2 in findItem or listItem = object3 in findItem:
print True
else:
print False
findItem(listofitems):
我是怎么离开的?
答案 0 :(得分:0)
import sys
if sys.version_info.major < 3:
input = rawinput
mylist = ['1', '2', 'a']
myset = {'3.14', 'b'}
def find(target, iterable):
for item in iterable:
if item == target:
return True
return False
assert find('2', mylist) is True
assert find('2', myset) is False
# print(find(input("Item to find")))