Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- with open('input.txt', 'r') as line:
- lis = [i.rstrip() for i in line .readlines() if i.rstrip()]
- out = open('output.txt', 'w')
- for i in sorted(set(lis)):
- out.write(" ".join([i, str(lis.count(i)), "\n"]))
- from collections import Counter
- from pathlib import Path
- d = dict(Counter(Path(r'input.txt').read_text().split()))
- Path(r'output.txt').write_text(
- '\n'.join([x + ' ' + str(d[x]) for x in sorted(d, key=lambda x: (-d[x], x))])
- )
- from collections import Counter
- from pathlib import Path
- d = dict(Counter(Path(r'input.txt').read_text().split()))
- Path(r'output.txt').write_text(
- '\n'.join([x + ' ' + str(d[x]) for x in sorted(d, key=lambda x: (-d[x], x))])
- )
- def remove_punctuation(s):
- punctuation = [".", ",", ":", ";", "!", "?"]
- answer = ''
- for i in range(len(s)):
- if s[i] not in punctuation:
- answer += s[i]
- return answer
- input_f = open("input.txt", "r")
- output_f = open("output.txt", "w")
- frequency = dict()
- words = []
- for line in input_f.read().split('\n')[:-1]:
- words.extend([remove_punctuation(word).lower() for word in line.strip().split()])
- for word in words:
- if word in frequency:
- frequency[word] += 1
- else:
- frequency[word] = 1
- keys_by_frequency = sorted(frequency.keys(), key=lambda x: frequency[x], reverse=True)
- answer_list = []
- temp = []
- frequency_num = frequency[keys_by_frequency[0]]
- for key in keys_by_frequency:
- if frequency[key] == frequency_num:
- temp.append(key)
- else:
- frequency_num = frequency[key]
- answer_list += sorted(temp)
- temp = [key]
- answer_list += sorted(temp)
- answer = ''
- for key in answer_list:
- answer += f'{key} {frequency[key]}\n'
- output_f.write(answer[:-1])
- input_f.close()
- output_f.close()
- input_f = open("input.txt", "r")
- output_f = open("output.txt", "w")
- l = []
- for command in input_f.readlines():
- action = command[0]
- num = int(command[1:-1])
- if action == "+":
- l.append(num)
- elif action == "-":
- try:
- l.remove(num)
- except:
- output_f.write("ERROR")
- quit(0)
- if len(l) != 0:
- output_f.write(' '.join([str(num) for num in sorted(l)]) + '\n')
- else:
- output_f.write("EMPTY")
- input_f.close()
- output_f.close()
- input_f = open("input.txt", "r")
- output_f = open("output.txt", "w")
- l = []
- for command in input_f.readlines():
- action = command[0]
- i = int(command[1:].split()[0]) - 1
- if action != "-":
- text = command[len(str(i)) + 2:]
- if action == "+":
- l.insert(i, text)
- elif action == "-" or action == "*":
- try:
- del l[i]
- if action == "*":
- l.insert(i, text)
- except:
- output_f.write("ERROR")
- quit(0)
- if len(l) != 0:
- for line in l:
- output_f.write(line)
- else:
- output_f.write("EMPTY")
- input_f.close()
- output_f.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement