File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Jython/Python and the fly likes Code from exercise of Core Python Programming Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Languages » Jython/Python
Bookmark "Code from exercise of Core Python Programming" Watch "Code from exercise of Core Python Programming" New topic
Author

Code from exercise of Core Python Programming

R. Jain
Ranch Hand

Joined: Aug 11, 2012
Posts: 367
    
    1

I have written a code for one exercise from the book 'Core Python Programming' as below... (The question is in the comment)

I want to know, whether I can use some other modules to better this code??
I just followed the simple for, if, else step to get the job done... Is there any other way where I can use pre-defined methods??
chris webster
Bartender

Joined: Mar 01, 2009
Posts: 1476
    
  11

I'm just learning Python myself, so I'm not sure if you can use other modules to achieve this. But one question you could ask is what happens if the files have different numbers of lines? Hint: check out izip_longest().


No more Blub for me, thank you, Vicar.
R. Jain
Ranch Hand

Joined: Aug 11, 2012
Posts: 367
    
    1

chris webster wrote:But one question you could ask is what happens if the files have different numbers of lines? Hint: check out izip_longest().

Yeah that thing I have taken care of after I posted the code..
We can also use map here (because, size of list returned by zip is equal to the size of shortest list...
Whereas in map, you get size of max list, with corresponding element for other list will be None in the following tuple)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Code from exercise of Core Python Programming
 
Similar Threads
variable problem
Comparing two huge files
help with assignment
Flagging duplicate lines when comparing the input from two seperate text files
how sort a array of files and directories.. ?