• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Code from exercise of Core Python Programming

 
Ranch Hand
Posts: 375
1
Python Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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??
 
Bartender
Posts: 2407
36
Scala Python Oracle Postgres Database Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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().
 
R. Jain
Ranch Hand
Posts: 375
1
Python Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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)
 
reply
    Bookmark Topic Watch Topic
  • New Topic