Feb-17-2021, 10:01 AM
(Feb-16-2021, 08:02 PM)snippsat Wrote: Is Sam🦄 so special that he need a function that only work for him.
So to give a example of what i mean.
def count_to_name(lst, name): count = 0 for element in lst: count += 1 if element == name: break return count if __name__ == '__main__': lst = ["able", "been", "state", "Sam", "beer"] name = 'been' if name not in lst: print(f'<{name}> not in list') else: result = count_to_name(lst, name) print(f'<{name}> appear at number <{result}> in list')You may see the point now and that is more flexible.
Output:<been> appear at number <2> in list
Change onlyname
and will get result number or that element is not in list.
name = 'car'
Output:<car> not in list
Oldman45 Wrote:You mention the need for a basic Python tutorial: could you please recommend one?Here something you can look at.
List of Free Python Resources here
Training sites most start with basic task,as eg Elementary in CheckiO.
CheckiO
exercism.io
Python Exercises, Practice, Solution
Hello Snippsat
That is really helpful, I will certainly study your code and then investigate the links you have kindly provided. Thanks again