Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def file_to_array(filename):
- file = open(filename, "r")
- file_content = file.read();
- file.close();
- return list(map(int, file_content.strip().split("\n")))
- def get_max_sum(arr):
- max = arr[0]
- for i in range(len(arr)-1):
- s = arr[i] + arr[i+1]
- if s > max:
- max = s
- if arr[-1] > max:
- max = arr[-1]
- return max
- def get_most_popular(arr):
- return max(arr, key=arr.count)
- print("----------------")
- for file in ["dane5-1.txt", "dane5-2.txt", "dane5-3.txt"]:
- print(file)
- arr = file_to_array(file)
- print("Max sum: {:d}".format(get_max_sum(arr)))
- print("Popular: {:d}".format(get_most_popular(arr)));
- print("----------------")
Advertisement
Add Comment
Please, Sign In to add comment