Scroll to see replies
def find(s):
d = {len(word): word for word in s.lower().split()}
return d[max(d.keys())]
Spoiler
find_longest_word = lambda s: sorted(s.split(' '), key=len)[-1]
def test_for_anagrams(first_word, second_word):
return sorted(first_word) == sorted(second_word)
def get_weekday(date_string):
return datetime.datetime.strptime(date_string, "%B %d %Y").strftime("%A")
def get_weekday(date_string):
return datetime.datetime.strptime(date_string, "%B %d %Y").strftime("%A")
Spoiler
Spoiler
Spoiler
Spoiler
def construct_dictionary_from_lists(names, ages, scores):
return {name: [ages, scores, 'pass' if scores >= 60 else 'fail'] for i, name in enumerate(names)}
Returns:
def integer_to_string(n):
n, units, tens, non_standard = [int(x) for x in str(n)], ["", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"], ["", "ten", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety"], ["eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen"]
return units[n[0]] + " thousand " + units[n[1]] + " hundred " * (n[1] != 0) + (non_standard[n[3] - 1] if 10 * n[2] + n[3] in [11, 12, 13, 14, 15, 16, 17, 18, 19] else tens[n[2]] + " " * (n[2] != 0) + units[n[3]])
def construct_dictionary(a, b, c):
return {a[n]: [b[n], c[n], ["fail", "pass"][int(c[n] >= 60)]] for n in range(len(a))}
def one_to_2D(a, r, c):
return [a[n * c: (n + 1) * c] for n in range(r)]
def multiplication_table(n):
return [[i * j for i in range(1, n + 1)]for j in range(1, n + 1)]
def construct_dictionary_from_lists(names, ages, scores):
return {name: [ages, scores, 'pass' if scores >= 60 else 'fail'] for i, name in enumerate(names)}
Returns:
def multiplication_table(n):
return [[i * j for i in range(1, n + 1)]for j in range(1, n + 1)]
Spoiler
def open_file(file_name):
return open(file_name).readlines()
def open_file(file_name):
return open(file_name).readlines()
def list_from_file(file_name):
# Make a connection to the file
file_pointer = open(file_name, 'r')
# You can use either .read() or .readline() or .readlines()
data = file_pointer.readlines()
# NOW CONTINUE YOUR CODE FROM HERE!!!
list_of_lines = []
for line in data:
list_of_lines.append(line.strip())
return list_of_lines
Last reply 2 days ago
Is MathsFM French Alevels good for a CS degree at top uni (OX, UCL, Durham etc)Last reply 4 days ago
OCR A-level Computer Science Paper 1 (H446/01) - 12th June 2023 [Exam Chat]Last reply 2 weeks ago
OCR A-level Computer Science Paper 2 (H446/02) - 19th June 2023 [Exam Chat]Last reply 3 weeks ago
AQA A-level Computer Science Paper 1 (7517 1A - 1E) - 12th June 2023 [Exam Chat]Last reply 1 month ago
Not receiving any response from University of Birmingham.Last reply 3 months ago
OCR GCSE Computer Science Paper 1 (J277/01) - 19th May 2023 [Exam Chat]Last reply 3 months ago
AQA GCSE Computer Science Paper 2 (8525/2) - 25th May 2023 [Exam Chat]Last reply 2 days ago
Is MathsFM French Alevels good for a CS degree at top uni (OX, UCL, Durham etc)Last reply 4 days ago
OCR A-level Computer Science Paper 1 (H446/01) - 12th June 2023 [Exam Chat]Last reply 2 weeks ago
OCR A-level Computer Science Paper 2 (H446/02) - 19th June 2023 [Exam Chat]Last reply 3 weeks ago
AQA A-level Computer Science Paper 1 (7517 1A - 1E) - 12th June 2023 [Exam Chat]Last reply 1 month ago
Not receiving any response from University of Birmingham.Last reply 3 months ago
OCR GCSE Computer Science Paper 1 (J277/01) - 19th May 2023 [Exam Chat]Last reply 3 months ago
AQA GCSE Computer Science Paper 2 (8525/2) - 25th May 2023 [Exam Chat]Writing a computer science personal statement: expert advice from universities
Open day questions: computer science students
Computer science degree personal statement example (2l) with review and advice
Computer science degree personal statement example (1z) with philosophy, Oxford offer, international applicant