Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- import json
- from pprint import pprint
- import re
- with open('grimm_tales.json') as f:
- all_stories = json.load(f)
- storiesCount = len(all_stories['stories'])
- print(storiesCount)
- # first and last sentence of a story
- print(all_stories['stories'][8]['story'][0])
- print(all_stories['stories'][8]['story'][-1])
- firstSent = []
- lastSent = []
- middleSent = []
- for story in all_stories['stories']:
- firstSent.append(story['story'][0])
- lastSent.append(story['story'][-1])
- # find middlepoint in the story
- middleIndex = (len(story['story']) - 1)/2
- middleSent.append(story['story'][int(middleIndex)])
- aList = [1,2,3,4,5]
- #minus 1 because the first element is index 0
- middleIndex = (len(aList) - 1)/2
- print (middleIndex)
- print (aList[int(middleIndex)])
- # random number from 0 to array length
- RandomNum = random.randint(1,storiesCount)
- span = 6
- firstPart = firstSent[RandomNum].split(' ')
- firstPartArray = [" ".join(firstPart[i:i+span]) for i in range(0, len(firstPart), span)]
- secondPart = lastSent[RandomNum].split(' ')
- secondPartArray = [" ".join(secondPart[i:i+span]) for i in range(0, len(secondPart), span)]
- for line in firstPartArray:
- print(line)
- print(' - ')
- for line in secondPartArray:
- print(line)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement