isupper は、「全てが大文字」を判定。 islower は、「全てが小文字」を判定。 not is lower は、「『全てが小文字』ではない」を判定。
>>> w = 'Abc'
>>> w.isupper()
False
>>> not w.islower()
True
[w for w in text5 if len(w) == 4] で、4文字の単語のみ抽出。FreqDist.keys() で頻度順に並べ替える。 単純に「長さ4」を抜き出しているので、!???のような、一般には単語と呼ばないものも出てくる。
>>> FreqDist([w for w in text5 if len(w) == 4]).keys()
['JOIN', 'PART', 'that', 'what', 'here', '....', 'have', 'like', 'with', 'chat', 'your', 'good', 'just', 'lmao', 'know', 'room', 'from', 'this', 'well', 'back', 'hiya', 'they', 'dont', 'yeah', 'want', 'love', 'guys', 'some', 'been', 'talk', 'nice', 'time', 'when', 'haha', 'make', 'girl', 'need', 'U122', 'MODE', 'much', 'then', 'will', 'over', 'were', 'work', 'take', 'U115', 'U121', 'song', 'U105', 'U156', 'does', 'even', 'seen', 'damn', 'more', 'come', 'only', 'hell', 'long', 'them', 'name', 'tell', 'away', 'baby', 'call', 'look', 'sure', 'U110', 'U114', 'play', 'NICK', 'cool', 'down', 'hate', 'many', 'said', 'sexy', 'ever', 'last', 'hear', 'life', 'live', 'LMAO', 'feel', 'give', 'mean', 'must', 'same', 'stop', 'very', '!!!!', 'What', 'cant', 'find', 'hugs', '????', 'U104', 'busy', 'hair', 'left', 'lost', 'nite', 'shit', 'fine', 'game', 'real', 'eyes', 'fuck', 'heya', 'kill', 'lets', 'sits', 'goes', 'keep', 'read', 'shut', 'true', 'wait', 'U168', 'else', 'free', 'near', 'nope', 'pick', 'This', 'U102', 'awww', 'bout', 'cold', 'gets', 'head', 'hehe', 'hope', 'male', 'stay', 'than', 'told', 'used', '.. .', 'U107', 'U119', 'babe', 'doin', 'face', 'home', 'into', 'kids', 'perv', 'wont', 'yall', 'year', 'Liam', 'U101', 'U132', 'Well', 'Yeah', 'hard', 'help', 'mind', 'once', 'show', 'week', '; ..', 'aint', 'best', 'book', 'care', 'crap', 'dang', 'days', 'dead', 'full', 'hmmm', 'hour', 'kiss', 'mine', 'neck', 'nick', 'pics', 'rock', 'runs', 'sick', 'soon', 'such', 'type', 'U139', 'U144', 'blue', 'case', 'heyy', 'hows', 'lady', 'made', 'sang', 'says', 'suck', 'wana', 'went', 'wife', 'word', 'Hiya', 'That', 'U108', 'U169', 'ahhh', 'alot', 'dear', 'dude', 'fast', 'hand', 'kick', 'okay', 'rule', 'took', 'wear', '))))', '<---', 'Last', 'Song', 'They', 'U103', 'U116', 'U120', 'U129', 'U142', 'U165', 'U197', 'U520', 'ball', 'blah', 'comp', 'done', 'food', 'goin', 'gone', 'knew', 'list', 'main', 'most', 'next', 'oops', 'part', 'pink', 'poor', 'ride', 'seem', 'send', 'sing', 'sock', 'thru', 'whos', '####', 'Have', 'Lime', 'U128', 'When', 'also', 'beer', 'boss', 'both', 'boys', 'cali', 'came', 'caps', 'easy', 'fall', 'feet', 'felt', 'fire', 'fool', 'hang', 'heck', 'idea', 'joke', 'kool', 'land', 'late', 'legs', 'lick', 'lose', 'luck', 'meds', 'meet', 'miss', 'nose', 'ohhh', 'roll', 'soul', 'till', 'wall', 'warm', 'wish', 'xbox', 'yoko', ',,,,', 'Like', 'ROOM', 'U117', 'U123', 'U126', 'U130', 'U133', 'U146', 'U154', 'U196', 'U219', 'U819', 'U820', 'U988', 'U989', 'beat', 'cute', 'date', 'door', 'each', 'evil', 'fart', 'glad', 'grrr', 'high', 'holy', 'hook', 'huge', 'jerk', 'kent', 'lame', 'line', 'lord', 'mmmm', 'none', 'ones', 'open', 'ouch', 'pain', 'pass', 'pfft', 'puff', 'quit', 'rest', 'self', 'shes', 'shot', 'sigh', 'team', 'turn', 'ugly', 'ummm', 'ways', 'woot', '((((', '2006', 'AKDT', 'CHAT', 'DING', 'Elev', 'Only', 'Same', 'THAT', 'U106', 'U109', 'U136', 'U141', 'U145', 'U148', 'U153', 'U163', 'Wind', 'Your', 'ahem', 'amen', 'army', 'band', 'bare', 'bend', 'butt', 'clap', 'deal', 'deop', 'died', 'elle', 'ello', 'gawd', 'gold', 'guyz', 'hail', 'half', 'hank', 'hawt', 'hick', 'hiii', 'hola', 'hump', 'hurt', 'imma', 'isnt', 'itch', 'jump', 'lead', 'mary', 'move', 'nana', 'note', 'orgy', 'piff', 'rain', 'ring', 'road', 'roof', 'rubs', 'skin', 'slap', 'slow', 'snow', 'soft', 'swim', 'toes', 'toss', 'town', 'tune', 'vote', 'wack', 'walk', 'wash', 'wazz', 'wine', 'yada', 'yawn', '!!!.', '1996', '<333', '<<<<', '>:->', '?!?!', '??!!', 'Ahhh', 'Come', 'Cool', 'DOES', 'DONT', 'Dang', 'Days', 'Down', 'Drew', 'FROM', 'From', 'Gosh', 'HAVE', 'Here', 'Heyy', 'High', 'John', 'Just', 'KoOL', 'Lets', 'Lies', 'Live', 'Lmao', 'Love', 'NONE', 'Nice', 'O.k.', 'Ohio', 'Okay', 'Poor', 'STOP', 'Stop', 'Sure', 'Tell', 'Tisk', 'U100', 'U111', 'U112', 'U138', 'U155', 'U170', 'U172', 'U175', 'U190', 'Ummm', 'WITH', 'YOUR', 'adds', 'ages', 'any1', 'area', 'argh', 'aunt', 'babi', 'bear', 'bite', 'blew', 'born', 'burp', 'cars', 'cash', 'cast', 'cell', 'chip', 'ciao', 'city', 'club', 'clue', 'cmon', 'corn', 'cost', 'deaf', 'deep', 'doll', 'drew', 'drop', 'dumb', 'ears', 'eats', 'eric', 'ewww', "ex's", 'fits', 'five', 'flaw', 'flow', 'foot', 'gays', 'gimp', 'golf', 'grrl', 'hall', 'haze', 'heal', 'hint', 'hits', 'hmph', 'hold', 'hott', 'howz', 'humm', 'john', 'kewl', 'kind', 'lawl', 'lies', 'limp', 'ltns', 'luvs', 'mama', 'mass', 'meat', 'mike', 'mins', 'moon', 'n9ne', 'newp', 'ohio', 'opps', 'park', 'past', 'phil', 'pies', 'plan', 'pool', 'porn', 'rent', 'rich', 'rofl', 'root', 'sand', 'sell', 'shop', 'side', 'sooo', 'sore', 'sort', 'spin', 'spot', 'temp', 'tick', 'tisk', 'tock', 'trip', 'twin', 'typo', 'tyvm', 'uses', 'wOOt', 'wats', 'whip', 'whoa', 'whud', 'wooo', 'yard', 'yeas', 'zone', '!...', '!???', '"...', '.op.', '1.98', '1.99', '100%', '10th', '1200', '1299', '18ST', '1900', '1930', '1980', '1985', '1cos', '2:55', '2DAY', '2Pac', '39.3', '3:45', '4.20', '45.5', '4:03', '64.8', '6:38', '6:41', '6:51', '6:53', '7:45', '9.53', '98.5', '98.6', '9:10', ':o *', "<3's", '<~~~', 'AKST', 'AWAY', 'Away', 'Awww', 'Back', 'Been', 'Bone', 'Born', 'Boyz', 'CALI', 'CAPS', 'COME', 'Came', 'Care', 'Chat', 'Chop', 'City', 'Ctrl', 'Cute', 'DAMN', 'Damn', 'Dawn', 'Deep', 'Does', 'Dood', 'Drop', 'Dude', 'ELSE', 'EVEN', 'Eggs', 'Elle', 'Even', 'Evil', 'Eyes', 'FACE', 'FINE', 'Fade', 'Food', 'Fort', 'GIRL', 'GOOD', 'GUYS', 'Girl', 'Good', 'GrlZ', 'HAHA', 'HALO', 'HERE', 'HOTT', 'HUGE', 'Haha', 'Hail', 'Hand', 'Hard', 'Help', 'Hero', 'Heya', 'Heys', 'Hill', 'Hold', 'Holy', 'Home', 'Hott', 'Hugs', 'Iowa', 'JUST', 'Jane', 'Jess', 'Joey', 'Judy', 'KNOW', 'Kent', 'Kewl', 'Kick', 'Kids', 'King', 'Kiss', 'Kold', 'LATE', 'LAst', 'LIVE', 'LONG', 'LOUD', 'Life', 'Lion', 'LoVe', 'Long', 'Look', 'Lord', 'MORE', 'MRIs', 'MUAH', 'Male', 'Maps', 'Mary', 'Matt', 'Meep', 'Mine', 'Mono', 'NAME', 'NTMN', 'Need', 'News', 'None', 'Nooo', 'Nope', 'Nova', 'OOPS', 'Ohhh', 'Oops', 'Over', "PM's", 'PMSL', 'Paul', 'Phil', 'Pour', 'Prof', 'QUIT', "RN's", 'ROFL', 'Rang', 'Reub', 'Rick', 'Road', 'Rock', 'Rofl', 'Room', 'Rule', 'Rush', 'Ruth', 'SEEN', 'SExy', 'SIZE', 'SOME', 'SSRI', 'Sat.', 'Save', 'Seee', 'Sexy', 'Show', 'Slip', 'Swim', 'TALK', 'TEXT', 'THEY', 'TIME', 'TYPR', 'Take', 'Talk', 'Teck', 'Then', 'Tide', 'Tiff', 'Time', 'Tina', 'Troy', 'Turn', 'Type', 'U113', 'U118', 'U134', 'U137', 'U143', 'U147', 'U149', 'U150', 'U158', 'U164', 'U181', 'U542', 'Uhhh', 'VBox', 'VVil', 'Very', 'WHEN', 'WHOA', 'WILL', 'Werd', 'Were', 'West', 'Will', 'Wyte', 'YALL', 'Yoko', 'York', 'able', 'abou', 'acid', 'addy', 'ahah', 'aime', 'akon', 'allo', 'ally', 'anal', 'anti', 'arms', 'asks', 'asss', 'bacl', 'barn', 'base', 'beam', 'bein', 'bell', 'benz', 'bied', 'bike', 'bird', 'bloe', 'blow', 'body', 'boed', 'bois', 'bomb', 'bone', 'bong', 'boom', 'boot', 'bowl', 'brad', 'brat', 'bred', 'brwn', 'buff', 'bugs', 'bull', 'bust', 'byes', 'caan', 'caca', 'calm', 'cams', 'card', 'cepn', 'chik', 'chit', 'choc', 'clay', 'coat', 'cock', 'coem', 'cook', 'cops', 'crib', 'crop', 'cums', 'cure', 'cuss', 'cyas', 'daft', 'dark', 'dawg', 'dick', 'dies', 'dint', 'dirt', 'disc', 'dman', 'docs', 'dogs', 'dojn', 'dork', 'dotn', 'draw', 'drug', 'duet', 'dump', 'dust', 'dyed', 'east', 'ebay', 'eeek', 'eeww', 'enuf', 'este', 'evah', 'exit', 'fair', 'fake', 'fawk', 'fear', 'feat', 'febe', 'firs', 'fish', 'fock', 'form', 'four', 'frst', 'gags', 'gals', 'gear', 'gees', 'geez', 'ghet', 'gift', 'giva', 'givs', 'goof', 'gooo', 'gosh', 'gray', 'grea', 'gret', 'grew', 'grin', 'guns', 'guts', 'haaa', 'halo', 'hawT', 'hazy', 'heat', 'heee', 'herE', 'herd', 'hgey', 'hide', 'hill', 'hiom', 'hogs', 'hong', 'hooo', 'hots', 'howl', 'http', 'hurr', 'icky', 'idnt', 'inch', "it's", 'jack', 'jail', 'jeep', 'jeff', 'jude', 'junk', 'jush', 'kept', 'keys', 'kina', 'king', 'kmph', 'knee', 'kold', 'kong', 'ladz', 'laid', 'lake', 'lala', 'lapd', 'lazy', 'lisa', 'lois', 'lol.', 'lool', 'loss', 'lots', 'loud', 'ltnc', 'lube', 'lung', 'lust', 'lyin', 'mahn', 'mame', 'mami', 'mang', 'mark', 'mauh', 'mena', 'menu', 'mess', 'mite', 'mkay', 'mode', 'mofo', 'moms', 'mono', 'nada', 'nads', 'nawp', 'nawt', 'nerd', 'nods', 'noth', 'nude', 'nuff', 'numb', 'o.k.', 'offa', 'ogan', 'ohwa', "ok'd", 'okey', 'ooer', 'oooh', 'orta', 'otay', 'out.', 'outa', 'outs', 'owww', 'page', 'paid', 'pair', 'pasa', 'peek', 'peel', 'perk', 'pigs', 'pimp', 'pine', 'plow', 'plus', "pm'n", "pm's", 'pmsl', 'poem', 'poll', 'poof', 'poop', 'poot', 'pope', 'pork', 'post', 'pour', 'pray', 'prep', 'prob', 'puke', 'pull', 'pure', 'push', 'puts', 'pwns', 'ques', 'quiz', 'raed', 'rang', 'rape', 'rats', 'ribs', 'rose', 'ruff', 'rush', 'saME', 'safe', 'salt', 'samn', 'sayn', 'scar', 'scuk', 'scum', 'sean', 'seat', 'seee', 'sent', 'serg', 'seth', 'sets', 'sexi', 'sexs', 'sext', 'shup', 'sign', 'sink', 'sips', 'site', 'size', 'slam', 'slip', 'smax', 'soda', 'sori', 'soup', 'span', 'spat', 'spit', 'ssid', 'star', 'sum1', 'surf', 'syck', 't he', 'tail', 'tall', 'tape', 'tart', 'teck', 'tend', 'tenn', 'tere', 'term', 'test', 'thah', 'ther', 'thje', 'thnx', 'thot', 'tiff', 'tips', 'tits', 'tjhe', 'tlak', 'toke', 'tooo', 'toop', 'tory', 'tthe', 'twit', 'urls', 'ussy', 'uyes', 'vamp', 'vega', 'vent', 'waaa', 'waht', 'wean', 'weed', 'west', 'wher', 'whew', 'whoo', 'whou', 'whys', 'wide', 'wild', 'wind', 'wins', 'wire', 'woah', 'wood', 'woof', 'wore', 'worl', 'wrap', 'wrek', 'wubs', 'wuts', 'xmas', 'yeee', 'yell', 'yes.', 'yesh', 'yess', 'yoll', 'yout', "yw's", 'z-ro']
ループ(for)の使い方の確認。
>>> for word in set([w for w in text6 if w.isupper()]):
... print word
...
SIR
MAYNARD
BORS
DEAD
TIM
MIDGET
LAUNCELOT
VOICE
MINSTREL
CUSTOMER
WOMAN
CRASH
CROWD
ARTHUR
VILLAGER
RANDOM
PATSY
DIRECTOR
ROGER
PARTY
THE
PRINCE
BRIDE
OF
SENTRY
PERSON
CRONE
MAN
HEADS
GUEST
BROTHER
FRENCH
CONCORDE
SOLDIER
PRISONER
DENNIS
KING
ENCHANTER
FATHER
GUARD
WITCH
C
PIGLET
DINGO
O
MIDDLE
S
W
WIFE
MONKS
SHRUBBER
NARRATOR
SUN
GALAHAD
VILLAGERS
NI
OLD
ARMY
WINSTON
SCENE
ZOOT
MASTER
LEFT
B
GIRLS
BEDEVERE
CART
N
SECOND
OFFICER
PRINCESS
ALL
LUCKY
BLACK
LOVELY
CHARACTER
HERBERT
AMAZING
GREEN
CHARACTERS
ROBIN
CRAPPER
GUARDS
INSPECTOR
A
HEAD
I
GOD
HISTORIAN
OTHER
U
GUESTS
Y
KNIGHTS
CAMERAMAN
RIGHT
KNIGHT
STUNNER
BRIDGEKEEPER
CARTOON
ANIMATOR