# -*- coding: utf-8 -*- """Untitled25.ipynb Automatically generated by Colaboratory. Original file is located at https://colab.research.google.com/drive/1LFBSpLYZlnJRoQA6udz5oUJaK-iihq_8 """ # A1 import random random.seed(123) mylist=[] for i in range(10): x = round(random.uniform(-0.1, 0.1),3) # print(x) # im not sure wanted this print mylist.append(x) print(mylist) # A2 mysecondlist = mylist.copy() mysecondlist.sort() print(mysecondlist) #A3 İndexin ne alak anlamadım ben açıklarsanız ona göre değiştireyim MINIMUM_OF_COPIED_LIST = mysecondlist[0] MAXIMIM_OF_COPIED_LIST = mysecondlist[-1] print("Minimum: " + str(MINIMUM_OF_COPIED_LIST) + "\n" + "Maximum: " + str(MAXIMIM_OF_COPIED_LIST)) #B1 poz = [i for i in mylist if i > 0] print(poz) print("Pozitive elements count: " + str(len(poz))) #B2 MINIMUM_OF_SUBLIST = min(poz) MAXIMUM_OF_SUBLIST = max(poz) AVERAGE_OF_SUBLIST = round(sum(poz) / len(poz), 3) print("Minimum: " + str(MINIMUM_OF_SUBLIST) + "\n" + "Maximum: " + str(MAXIMUM_OF_SUBLIST) + "\n" + "Average: " + str(AVERAGE_OF_SUBLIST)) with open('Amazon - 2018.txt') as f: text = f.read() # print(text) # with open('LM_SentimentWordLists_2018_Positive.txt') as f: # wl = f.read() # print(wl) # print(text) text = text.split() text = [i.lower() for i in text] text.pop(0) # remove url print(text) import string # mystringpunch= string.punctuation+"\’" # table = str.maketrans('', '', mystringpunch) table = str.maketrans('', '', string.punctuation) text_after_remove_punch = [w.translate(table) for w in text] print(text_after_remove_punch) text_word_count= len(text_after_remove_punch) uniq = set(text_after_remove_punch) print(type(uniq)) mydict = {} for i in uniq: mydict[i] = text_after_remove_punch.count(i) # print(mydict) for key in mydict: if mydict.get(key) > 25: print("Word: " + str(key) + " Count: " + str(mydict.get(key)) ) with open('LM_SentimentWordLists_2018_Positive.txt') as f: LM = f.read() LM = LM.split() LM = [i.upper() for i in LM] print(LM) uniq_list = list(uniq) print(len(uniq_list)) print(text_after_remove_punch.count(uniq_list[505])) def ML_words_exist_how_many_times_in_text(uniq_list, LM): total_sum = 0 for i in uniq_list: if i.upper() in LM: total_sum += text_after_remove_punch.count(i) return total_sum print(ML_words_exist_how_many_times_in_text(uniq_list, LM)) format_text = "The words from the LM word list appear {THE_NUMBER_OF_TIMES} times in the text".format(THE_NUMBER_OF_TIMES=ML_words_exist_how_many_times_in_text(uniq_list, LM)) print(format_text) #text_word_count print(len(LM))