944,057 Members | Top Members by Rank

Ad:
  • Python Discussion Thread
  • Unsolved
  • Views: 3244
  • Python RSS
Jan 17th, 2007
0

creating batch in python

Expand Post »
[code]

result=[]
list = int(raw_input("enter the length of list:"))
size_of_batch=int(raw_input("enter the size of batch:"))

def createBatch(lst):
lenLst = len(lst)
if lenLst > size_of_batch:
no_of_batch=lenLst/size_of_batch
last_entry_batch=lenLst%size_of_batch
first_index=0
last_index=size_of_batch
else:
no_of_batch=0
first_index=0
last_entry_batch=lenLst
newList = lst[0:last_entry_batch]
runChangeState(result,newList)
return

while no_of_batch != 0:
newList = lst[first_index:last_index]
runChangeState(result,newList)
first_index=first_index+size_of_batch
last_index=last_index+size_of_batch
no_of_batch = no_of_batch-1


if no_of_batch==0:
newList = lst[first_index:last_index]
runChangeState(result,newList)


def runChangeState(result,newList):
result.append(newList)
#return newList

createBatch(range(list))
for each in result:
print each


[inlinecode]
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
sharma_vivek82 is offline Offline
18 posts
since Mar 2006
Jan 17th, 2007
0

Re: creating batch in python

Code tags are particularly important with Python code since they preserve the indentations. Without the proper indentations Python code becomes hard to read and understand!

I will show the needed tags in reverse so they don't activate:
at the end of your code add this tag [/code]
at the start of your code add tag [code=Python]
Moderator
Reputation Points: 1333
Solved Threads: 1403
DaniWeb's Hypocrite
vegaseat is offline Offline
5,792 posts
since Oct 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Python Forum Timeline: On a thumb drive.
Next Thread in Python Forum Timeline: week from given year





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC