Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #file1 = open('./1/input.txt', 'r')
- #lines = file1.readlines()
- lines = ["oneghj","neighthreeb", "2sevenjddn2hbk5f6nine"]
- words = ["one", "two", "three", "four", "five", "six", "seven", "eight", "nine"]
- sum = 0
- for line in lines:
- count = 0
- nums = []
- indeces = []
- # find the words, take down the index of the first letter and the number value
- for w in range(len(words)):
- i = line.find(words[w])
- if i > -1:
- indeces.append(i)
- nums.append(str(w+1))
- # find the numbers, take down their indeces and values
- for l in range(len(line)):
- c = line[l]
- if c.isdigit():
- #print(l)
- indeces.append(l)
- nums.append(c)
- # find the lowest index and max index (first and last number, if if their the same)
- mn = min(indeces)
- mx = max(indeces)
- print(nums[indeces.index(mn)] + nums[indeces.index(mx)])
- # concatenate the strings then add to the total
- sum += int(nums[indeces.index(mn)] + nums[indeces.index(mx)])
- print(sum)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement