이명교 | 30 Jul 01:13 2014

Comparing two different text file

Hello 

I'd like to make new list from 'first.txt' which is not overlapped 'second.txt'.

I tried several times but I couldn't find right answer.

output was '[]'

 

First, Import two different text file and read as a list.

If  'first.txt' has same value as second.txt', don't append to new list.

'first.txt' has many same values.

'second.txt is like standard list.

 

Thanks.

 

 

 

#!/usr/bin/env python
list1 = []
list2 = []
list3 = []
list4 = []
#imports list from first text file
inf1 = open('first.txt')
for line in inf1.readlines():
    list1.append(line)
    list1 = line[:-1].split('\n')
#imports list from first text file
inf2 = open('second.txt')
for line in inf2.readlines():
    list2.append(line)
    list2 = line[:-1].split('\n')
#append items of list1
for a in list1:
    if a not in list1:
        list3.append(a)
#append items list1 don't have
for b in list3:   
    if b not in list2:
        list4.append(b)

ouf = open('new.txt', 'w')

ouf.writelines(list4)

 




#first.txt

#second.txt 

SS18SSX1
SS18SSX1
SS18SSX2
EWSR1FLI1
EWSR1FLI1
EWSR1FLI1
EWSR1ERG
EWSR1ERG
EWSR1FLI1
EWSR1FLI1
EWSR1FLI1
EWSR1FLI1
EWSR1FLI1
EWSR1FLI1
EWSR1FLI1
EWSR1FLI1
EWSR1FLI1
EWSR1FLI1
EWSR1FLI1
EWSR1FLI1
EWSR1ERG
EWSR1ERG
EWSR1FLI1
EWSR1FLI1
EWSR1FLI1
EWSR1FLI1
EWSR1ERG
EWSR1ERG
EWSR1ERG
EWSR1ERG
EWSR1ERG
EWSR1ERG
EWSR1FLI1
EWSR1FLI1
EWSR1FLI1
EWSR1FLI1
EWSR1ERG
EWSR1ERG
EWSR1FLI1
EWSR1FLI1
EWSR1FLI1
EWSR1FLI1
EWSR1FLI1
EWSR1EWSR1
EWSR1FLI1
EWSR1FLI1
EWSR1EWSR1
EWSR1FLI1
EWSR1FLI1
EWSR1ERG
EWSR1ERG
EWSR1ERG
EWSR1ERG
EWSR1ERG
EWSR1ERG
EWSR1FLI1
EWSR1FLI1
EWSR1FLI1
EWSR1FLI1
EWSR1FLI1
EWSR1FLI1
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IP1MYL6
BCAMPES1
NUP98PRRX2
ALPPPTPRU
NUP188POLR2A
ETV5LOC284889
PAX3FOXO1
DDX42MT1F
C7orf50FLNA
ETV6RUNX1
PIK3R2BC040735
RPL28GLB1
CTTNMYC
ZHX2DDX52
NEAT1CSF3R
PLXNB2CSNK1E
ATP5A1NEFL
KIF3BSMC2
RMI2SPATA20
CSH1RRBP1
EIF2AK1DBNL
EIF3BPOLA2
RPL21ELF3
MED24MED24
CELSR1MOB3A
C14orf2SLTM
CAPN13FKBP11
TAF15NR4A3
ADD1bK250D10.C22.8
BTF3GGA1
LAMP1PSD
ADCY5GLIS1
RPL14ZNF167
SYPCPB1
ZIM2PRR14
SCARB2CYP19A1
CDKL5DGCR8
DRG1C1orf144
EEF1E1DSC2
RPS6KB1PCNXL2
USF1MLLT6
NDRG1ATP2A2
H19TCEA3
AP2A1NECAB3
BCRABL1
IL6LOC541472
RAD9APPP1CA
FUSATF1
GSDMBMIR3134
CDH11USP6
FBXO34SSRP1
MLLGMPS
EIF3CLMED24
PSMD8HDLBP
COL3A1CLU
MLLGMPS
CNBPUSP6
PPP6R2INTS3
ITGB1BP1CPSF3
DHCR24Unknown
MDC1Unknown
ANXA2SPRR2A
VPS13DPITPNB
ABCC10PGBD5
POU6F1QSOX1
ZNF79EVL
TMX2PICALM
IGFBP3SLC2A3
MPHOSPH10AES
UPF3BUnknown
B2MPCBP1
RBBP6CEP350
CRYL1ATPAF1
EPHA5MALAT1
AESMPHOSPH10
MYADMSPIDR
AK128525MALAT1
MLLGAS7
CD3EORAI2
PNPLA7APOE
TGFBITGFBI
FUSMARS
TUBB4BITPRIP
DAZAP2BOLA2
MPHOSPH10AES
TTC21BFKBP8
LTBRWDTC1
STXBP5FAM126A
JUPECHS1
MYH9RAPGEF1
BRPF3N4BP2L2
EZRINSR


 

 

 

 

 






_______________________________________________
Tutor maillist  -  Tutor <at> python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
Deb Wyatt | 25 Jul 03:58 2014

Re: Read a file, Load a dictionary

 assuming you're
>  using version 3.5
> 

How do you get version 3.5?  Python.org shows 3.41 as being the latest.

Deb in WA, USA

____________________________________________________________
FREE ONLINE PHOTOSHARING - Share your photos online with your friends and family!
Visit http://www.inbox.com/photosharing to find out more!

_______________________________________________
Tutor maillist  -  Tutor <at> python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Glenn Lester | 25 Jul 00:50 2014
Picon

Read a file, Load a dictionary


I have been looking around for a way to read a comma delimited csv file and then load it into a dictionary. So far any of my usual sources don't deal with such simple stuff.

My current code is


# create a dictionary (dict) to store the order # and Remark
    testVariables = {}

# Read the file and load the dict
    input_file = open('test1Comma.csv', 'rU')
    for line in input_file:


I'm stuck on the code that comes next. what line of code loads the dict?

my csv file has 2 lines shown below.

AUTO-TEST-0021,REMARK 1
AUTO-TEST-0022,REMARK 2

Thanks in advance for the help.
--

_______________________________________________
Tutor maillist  -  Tutor <at> python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
Allahondoum Mbaibarem | 24 Jul 12:11 2014
Picon

Security and Reliability of Python

I'm new at python and I would like to have knowledge about the Security and the Reliability factor of Python thank you.

_______________________________________________
Tutor maillist  -  Tutor <at> python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
Allahondoum Mbaibarem | 24 Jul 11:09 2014
Picon

Inquiry

Please I would like to know about the Security and the Reliability of Python. Thank you

_______________________________________________
Tutor maillist  -  Tutor <at> python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
jitendra gupta | 24 Jul 13:35 2014
Picon

Error Handling in python

Hi All

My shell script is not throwing any error when I am having  some error in Python code. 

~~~~~~~~ test.py ~~~~~~
def main():
    print "Test"
    #some case error need to be thrown
    raise Exception("Here is error")

if __name__ == "__main__"
    main()
~~~~~~
~~~~~~~~ second.py ~~~~~~
def main():
    print "Second function is called"


if __name__ == "__main__"
    main()
~~~~~~

~~~~~ shellTest.sh ~~~~~~~
python test.py
python second.py
~~~~~~~~~~~~~~~~~~~~~~~

In this case, I dont want to run my second.py 
Even I am throwing error from my test.py, but still second.py is getting executed, which i dont want, 


Thanks & Regards
Jitendra

_______________________________________________
Tutor maillist  -  Tutor <at> python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
Wolfgang Maier | 23 Jul 11:28 2014
Picon

binning data and calculating means of classes

On 07/23/2014 03:36 AM, LN A-go-go wrote:
 >
 > with your help.  I have been working the last few days, I am sorry to
 > say, unsuccessfully, to calculate the mean (that's easy), split the data
 > into sub-groups or secondary means - which are the break values between
 > 4 classes.  Create data-sets with incursive values.  I can do it with
 > brute force (copy and paste) but need to rise to the pythonic way and
 > use a while loop and a nested if-else structure.  My attempts have been
 > lame enough that I don't even want to put them here.

A while loop with an if inside is indeed a very plausible solution, so 
it would be interesting to see your attempts.

 > int_list
 > [36, 39, 39, 45, 61, 54, 61, 93, 62, 51, 47, 72, 54, 36, 62, 50, 41, 41,
 > 40, 62, 62, 58, 57, 54, 49, 43, 47, 50, 45, 41, 54, 57, 57, 55, 62, 51,
 > 34, 57, 55, 63, 45, 45, 42, 44, 34, 53, 67, 58, 56, 43, 33]
 >>>> int_list.sort()
 >>>> int_list
 > [33, 34, 34, 36, 36, 39, 39, 40, 41, 41, 41, 42, 43, 43, 44, 45, 45, 45,
 > 45, 47, 47, 49, 50, 50, 51, 51, 53, 54, 54, 54, 54, 55, 55, 56, 57, 57,
 > 57, 57, 58, 58, 61, 61, 62, 62, 62, 62, 62, 63, 67, 72, 93]
 >>>> flo_list = [float(integral) for integral in int_list]

While this last line shows that you've started using list 
comprehensions, which is a good thing, converting your data to floating 
point is not a good idea. It is completely unnecessary and (though 
probably not relevant here) can compromise the accuracy of calculations 
due to inherent rounding errors.
I guess you are doing this to prevent subsequent rounding of the result 
of sum(int_list)/len(int_list).
This is a Python2-specific issue and, personally, I think that as a 
beginner you should use Python3, where (among other things) this is not 
a problem.
If you want to stick to Python2 for whatever reason then do:

from __future__ import division

after which integer divisions return a float if required just as in Python3.

 >>> sum(int_list)/len(int_list)
51.31372549019608

 >>>> flo_list
 > [33.0, 34.0, 34.0, 36.0, 36.0, 39.0, 39.0, 40.0, 41.0, 41.0, 41.0, 42.0,
 > 43.0, 43.0, 44.0, 45.0, 45.0, 45.0, 45.0, 47.0, 47.0, 49.0, 50.0, 50.0,
 > 51.0, 51.0, 53.0, 54.0, 54.0, 54.0, 54.0, 55.0, 55.0, 56.0, 57.0, 57.0,
 > 57.0, 57.0, 58.0, 58.0, 61.0, 61.0, 62.0, 62.0, 62.0, 62.0, 62.0, 63.0,
 > 67.0, 72.0, 93.0]
 >>>> sum(flo_list)
 > 2617.0
 >>>>  totalnum = sum(flo_list)

stop generating references if you're not going to use them later!
Confuses you and others.

 >>>> len(flo_list)
 > 51
 >>>> mean = sum(flo_list)/len(flo_list)
 >>>> mean
 > 51.31372549019608

So, you know how to calculate the total mean. For the means of 
subsamples what you have to do is to apply that same logic to subsamples 
of the data, which you have to generate.
Without going through the lists of values several times, however, I 
cannot think of any simple implementation of this, which does not 
involve plenty of novel concepts.
One fairly simple approach would be through a while loop as you 
suggested, but as said before, for loops are often more elegant in 
Python. I guess the following code is roughly what you had in mind ?

breakpoints = [your_list_of breakpoints]
large_value_buffer = []
int_list_iter = iter(int_list) # see comment below
for breakpoint in breakpoints:
	sublist = large_value_buffer
	for value in int_list_iter:
		if value < breakpoint:
			sublist.append(value)
			if large_value_buffer:
				large_value_buffer = []
		else:
			if sublist:
				print(sum(sublist)/len(sublist))
				large_value_buffer.append(value)
			break

Essentially, you should know all elements of this small program except 
the iter(int_list). Essentially, this gives you a one-time iterator, 
which cannot be reused or reset, to use in the inner for loop. This 
prevents starting from the beginning of the list every time.

Since this is probably too complicated for you to work it out by 
yourself at this stage, I decided to give you the complete code, but 
make sure you understand what it does, especially think about what the 
large_value_buffer is doing.

One problem with this code is that it silently skips empty bins. Maybe 
that's something for you to work on ?

Best,
Wolfgang

_______________________________________________
Tutor maillist  -  Tutor <at> python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Eric Dannewitz | 23 Jul 01:10 2014

Getting a directory listing with Python to MySQL

Hello list, I'm new. I've done a few things in Python, but this one is posing problems.

What I want to do is be able to parse a directory, say /Volumes/Stuff/Files/, and all the directories that might be in there, and be able to pick out file name, size, date modified, etc, and send that to a MySQL database. Any ideas? Sounds like it should be easy but......
_______________________________________________
Tutor maillist  -  Tutor <at> python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
jarod_v6@libero.it | 22 Jul 13:10 2014
Picon

How to show dictionary item non present on file

Hin there!!!

I have a niave question on dictionary analysis: 
If you have a dictionary like this:
diz
Out[8]: {'elenour': 1, 'frank': 1, 'jack': 1, 'ralph': 1}

and you have a list and you want to know which  keys are not present on my 
dictionary the code are simple.
for i in diz.keys():
   ...:     if i in mitico:
   ...:         print "NO"
   ...:     else:
   ...:         print i
   ...:         
NO

But I havethis problem I have a file and I want to know which elements are not 
present on my file from dictionary.
 more data.tmp 
jack	1
pippo	1
luis	1
frate	1
livio	1
frank	1

with open("data.tmp") as p:
    for i in p:
        lines= i.strip("\n").split("\t")
        if not diz.has_key(lines[0]):
   ....:             print i
   ....:             
pippo	1

luis	1

frate	1

livio	1

The output I want is to have :
ralph and 'elenour.. how can I do this?
thanks in advance!

_______________________________________________
Tutor maillist  -  Tutor <at> python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

yarteydegreat2@gmail.com | 21 Jul 08:57 2014
Picon

Unhandled exception

I just want to know if an unhandled exception is a bug in my programs!

Degreat

_______________________________________________
Tutor maillist  -  Tutor <at> python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
keith papa | 20 Jul 22:57 2014

Is this possible for a newbie?

Am a newbie to programming and I started learning python days ago. I have this idea I want to execute, am a big sport and fantasy fan and I wanted to create something that will make it things a little easy for me. My idea is simple I want to create a program that I can enter name and some information about a player, for example: 


NFL plays:


Jamaal Charles RB : ATT 259 , YDS 1,287 , AVG 5.0, TD 12, REC 70


Tony Romo QB: CMP% 63.9, YDS 3,828 , TD 31, INT 10, Rating 96.7


Dez Bryant WR: REC 93, YDS 1,233, AVG 13.3, LNG 79, TD 13


and other players information.


I want to be able to ask the program which QB is best on my list and it give me the names of all the QB on my list, or ask for WR on my list and it gives me all the WR on my list, and also I want to be able to crossed out name simply by typing the players name.

What do I need to lean in order to accomplish this? string, variable functions?

feel free to ask any questions.
_______________________________________________
Tutor maillist  -  Tutor <at> python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Gmane