Skip to content

Instantly share code, notes, and snippets.

View tombrad's full-sized avatar

Tomas Bradanovic tombrad

View GitHub Profile
@tombrad
tombrad / test7
Last active December 11, 2015 20:59
aprenda pyton en 3 dias
colon=":"
count=0
total=0
fname = raw_input("Enter file name: ")
fh = open(fname)
for line in fh:
if not line.startswith("X-DSPAM-Confidence:") : continue
pos = line.find(colon)
pos=int(pos)
num=line[pos+1:40]
@tombrad
tombrad / test2
Created January 28, 2013 23:01
aprenda python en 3 días
largest = -1
print "Before", largest
for value in [3,41,12,9,74,15] :
if value > largest :
largest = value
print largest,value
@tombrad
tombrad / test91
Last active December 11, 2015 22:08
aprenda python en 3 días
name = "mbox-short.txt" # the name of the file with the text source
handle = open(name) # "store" the file temporally into a handle variable
cou=dict() # defines a dictionary named cou
correos=list() # defines a list called correos
#correos create a list with every mail address
for line in handle: # check for every line of the file with text
if not line.startswith("From:") : continue # if the line don´t start with "From:" pass to the next line
words=line.split() # else store the line in the list named words with every component
# separated by a space splitted as a different ellement
@tombrad
tombrad / text10
Created January 29, 2013 22:10
aprenda python en 3 dias
name = "mbox-short.txt"
handle = open(name)
dic=dict() # defines an empty dictionary
for line in handle:
if not line.startswith("From ") : continue #select only lines with "From "
words=line.split() #turns string into list of words
word2=words[5] #select hour
word2=word2[:2] #slice 2 first characters
dic[word2]=dic.get(word2,0)+1 #accumulate in dictionary
@tombrad
tombrad / gist:4697060
Last active March 14, 2024 15:50
8.4 Open the file romeo.txt and read it line by line. For each line, split the line into a list of words using the split() function. The program should build a list of words. For each word on each line check to see if the word is already in the list and if not append it to the list. When the program completes, sort and print the resulting words …
fname = raw_input("Enter file name: ")
fh = open(fname)
lst = list() # list for the desired output
for line in fh: # to read every line of file romeo.txt
word= line.rstrip().split() # to eliminate the unwanted blanks and turn the line into a list of words
for element in word: # check every element in word
if element in lst: # if element is repeated
continue # do nothing
else : # else if element is not in the list
lst.append(element) # append
@tombrad
tombrad / gist:4726943
Created February 6, 2013 23:40
Curso VBA-1
Private Sub tdolares_Exit(ByVal Cancel As MSForms.ReturnBoolean)
tpesos.text = Val(tdolares.text) * 500
End Sub
@tombrad
tombrad / gist:4726952
Created February 6, 2013 23:42
Curso VBA-2
Private Sub tpesos_Exit(ByVal Cancel As MSForms.ReturnBoolean)
tdolares.text = Val(tpesos.text) /500
End Sub
@tombrad
tombrad / gist:4726958
Created February 6, 2013 23:43
Curso VBA-3
Private Sub CommandButton1_Click()
tdolares.Text = “”
tpesos.Text = “”
End Sub
@tombrad
tombrad / gist:4726962
Last active December 12, 2015 06:08
Curso VBA-4
Private Sub CommandButton1_Click()
tdolares.Text = “”
tpesos.Text = “”
End Sub
Private Sub tdolares_Change()
End Sub
Private Sub tdolares_Exit(ByVal Cancel As MSForms.ReturnBoolean)
@tombrad
tombrad / gist:4726988
Created February 6, 2013 23:46
Curso VBA-5
Sub prueba1()
UserForm1.show
End Sub