numarasının "değişkeni" gösterilmemesi burada yeniyim. Bu aptal soru için üzgünüm.Python
Birçok .txt dosyasında (3979 dosya), örneğin "Olumlu", "Olumsuz" ve "Tarafsız" gibi sözcükleri saymaya çalışıyorum. Saydıktan sonra, en yüksek sayımı olanı seçmek istiyorum.
Belirli bir metinde 5 Olumlu, 1 Negatif ve 0 Tarafsız olduğunu varsayalım.
ben
largest = max(myRev)
kullanırsanız gibi
myRev = [Positive, Negative, Neutral]
Sonra bir liste koymak ve ben largest
çağırdığınızda, bu durumda
5
verir edecek , Değerini göstermek istiyorum Positive
, Negative
Ya Neutral
(>>> budur benim ana soru) Ben koymak istiyorum Bundan sonra
Positive
, Negative
veya böyle eklenmiyor başka listeye Neutral
...
ReviewList = []
ReviewList.append(maxNr)
ve ben böyle devam
Reviewlist = [Positive, Negative, Neutral, Neutral,... Neutral]
ve benzeri ReviewList
haline şey ararsanız keşke ..
Bunun için ne yapabilirim?
listOfReview = []
for i in xrange(0,3979):
f = open("ReviewsOutput%i.txt" %i, "r")
myOutput = f.read()
Positive = myOutput.count("Positive")
Negative = myOutput.count("Negative")
Neutral = myOutput.count("Neutral")
myRev = [Positive, Negative, Neutral]
largest = max(myRev)
listOfReview.append(largest)
f.close
Bize bazı kodları göster. – WhoAmI
Hehe, Ben bu konuda çok emin değilim :( Ama benim soruma kodumu ekledim ... – Woro
'collections.Counter' bir göz atın ([belgeler] (https://docs.python.org/ 2/library/collections.html # counter-objects)) – Peter