[ n**2 for n in range(1,6)]
[(x,y) for x in range (1,4) for y in range (1,4)]
[x+y for x in range (1,4) for y in range (1,4)]
[x for x in range(1,30) if x%2==0]
a="lol"
a.upper()
[x.upper() for x in ["This", "week", "will", "be", "fun"]]
You have been provided two functions stringList which given a string as an argument returns a list of strings and count_words which also takes a string and converts it to list of strings and then returns a list of the count of letters for each string
def stringList(str1):
return str1.split()
stringList("This is a test run")
def count_letters_in_words(str1):
w_lst=stringList(str1)
lst=[]
for word in w_lst:
l=len(word)
lst=lst+[l]
return lst
def count_letters_in_words2(str1):
w_lst = stringList(str1)
return [len(i) for i in w_lst]
count_letters_in_words2("This is a test run")
def count_letters_in_words2(str1):
w_lst = stringList(str1)
return [len(word) for word in w_lst]
count_letters_in_words2("This should be fun")
A list of daynames and a fucntion which returns day of the week for a date are provided Hint: you need two ranges one for day starting from 1 and going to 31 and another one for month starting from 1 going to 12. Using these and the year which comes as an argument and use the function day_of_week (Problem 2) in the if part of list comprehension to check if a given date is ‘Friday’ and also check if the day is equal to 13.
day_names = ['Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday']
def day_of_week(d,m,y):
day = (((13*m+3) // 5 + d + y + (y // 4) - (y // 100) + (y // 400)) %7)
return day_names[day]
day_of_week(16,7,2022)
def unlucky(y):
return [(d,m,y) for m in range(1,13) for d in range (1,32) if d == 13 and day_of_week(d,m,y) == "Friday"]
unlucky(2019)