There was a question i came arcoss and I am new to python. Was trying it out but still get an error:
You are given a list of strings, using list comprehensions create a new list of strings called ‘my_list’ , which only contain the strings that have odd length.
my solution:
def main():
str_list = [‘given’, ‘intern’, ‘InterviewBit’, ‘network’, ‘local’, ‘multiple’, ‘define’, ‘nodes’, ‘algorithm’, ‘allows’, ‘community’, ‘phase’, ‘single’]
my_list = [x for x in str_list if len(str_list)%2 == 1]
print(my_list)
return 0
if name == ‘main’:
main()
the solution they want is in my_list… pls help me out