I have a input format XX:YY:ZZ and the start value may be 'n' digit numbers for X,Y,Z.
So I have to assign the numbers based on the above format ( Format may change)
Say
Example - 1
Inputs :
Number Format :- XX:YY:ZZ
Start Values for
X = 1
Y = 5
z = 1
I have to create 5 numbers with +1 increment for 'Y'direction value
Here 'Z' will be constant
XX:YY:ZZ
010501
010601
010701
010801
010901
011001
Example - 2
------------------
Number Format :- X:YY:Z
X = 1
Y = 5
z = 1
I have to create the numbers with +1 increment for 'X' & 'Y'direction value
Here 'Z' will be constant
X:YY:Z
010501
010601
010701
010801
010901
011001
020501
020601
020701
020801
020901
021001
How to arrive at these numbers based on the format and the start numbers?
Thanks
PSB
6 2907 bvdet 2,851
Expert Mod 2GB
I have a input format XX:YY:ZZ and the start value may be 'n' digit numbers for X,Y,Z.
So I have to assign the numbers based on the above format ( Format may change)
Say
Example - 1
Inputs :
Number Format :- XX:YY:ZZ
Start Values for
X = 1
Y = 5
z = 1
I have to create 5 numbers with +1 increment for 'Y'direction value
Here 'Z' will be constant
XX:YY:ZZ
010501
010601
010701
010801
010901
011001
Example - 2
------------------
Number Format :- X:YY:Z
X = 1
Y = 5
z = 1
I have to create the numbers with +1 increment for 'X' & 'Y'direction value
Here 'Z' will be constant
X:YY:Z
010501
010601
010701
010801
010901
011001
020501
020601
020701
020801
020901
021001
How to arrive at these numbers based on the format and the start numbers?
Thanks
PSB
This is not ideal, but it seems to meet your requirements: - def format_numbers(X,Y,Z,n,u):
-
x,y,z = X,Y,Z
-
outList = []
-
while x <= u:
-
while y <= u:
-
if n == 0:
-
return outList
-
else:
-
outList.append('%02d%02d%02d' % (x, y, z))
-
y += 1
-
n -= 1
-
y = Y
-
x += 1
-
return outList
-
-
print format_numbers(1,5,1,8,10)
-
-
>>> ['010501', '010601', '010701', '010801', '010901', '011001', '020501', '020601']
Thanks for the reply.
But the number format will be changing
Say:
a) Format :- X:Y:Z
Then the values will be 111 to 991 ( Z = 1 Constant,Xmin,Ymin = 1 and Xmax,Ymax = 9)
b) Format :- XX:YY:ZZ
Then the values will be
010101 to 999901 ( Z = 01 Constant, Xmin,Ymin = 01 and Xmax,Ymax = 99)
c) Format :- XX:Y:ZZ
Then the values will be
01101 to 99901 ( Z = 01 Constant, Xmin =01,Ymin = 1 and Xmax =99,Ymax = 9)
d) Format :- XX:Y:ZZ
Then the values will be
01101 to 99199 ( Y = 1 Constant, Xmin =01,Zmin =0 1 and Xmax =99,Zmax = 99)
and soon.
Is it possible to create the above formating in amore generic way.
Input will be format and the start index of X,Y,Z (But one index will be constant,out of three)
-PSB
-PSB
Instead of giving constant value (say 4 in this case),is it possible to give variable name as shown below and get the solution
[code]
Existing:
>>> outList =[]
>>> outList.append('%04d%04d%04d' % (100, 51, 1))
>>> [ '010000510001']
Required:
Index will be varying based on the format
>>> Index = 2
>>> outList =[]
>>> outList.append('%0Indexd%0Indexd%0Indexd' % (100, 51, 1))
>>> outList
['100d51d1d']
But I am getting the expected output.May be my syntax is wrong.Correct me for the format
-PSB
bvdet 2,851
Expert Mod 2GB
Instead of giving constant value (say 4 in this case),is it possible to give variable name as shown below and get the solution
Existing:
>>> outList =[]
>>> outList.append('%04d%04d%04d' % (100, 51, 1))
>>> [ '010000510001']
Required:
Index will be varying based on the format
>>> Index = 2
>>> outList =[]
>>> outList.append('%0Indexd%0Indexd%0Indexd' % (100, 51, 1))
>>> outList
['100d51d1d']
But I am getting the expected output.May be my syntax is wrong.Correct me for the format
-PSB
You could do something like this: - >>> def plcs(n,p):
-
... n = str(n)
-
... return (p-len(n))*'0'+n
-
...
-
>>> '%s%s%s' % (plcs(5,4), plcs(6,4), plcs(8,4))
-
'000500060008'
-
>>>
You could do something like this: - >>> def plcs(n,p):
-
... n = str(n)
-
... return (p-len(n))*'0'+n
-
...
-
>>> '%s%s%s' % (plcs(5,4), plcs(6,4), plcs(8,4))
-
'000500060008'
-
>>>
Thanks BV,
It washelpful
bvdet 2,851
Expert Mod 2GB
Thanks BV,
It washelpful
You are welcome. A generic function to generate number sequence strings is a bit more work than I have time for at the moment.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: shank |
last post by:
I'm creating a spreadsheet online via ASP. I have the following at the page
top...
<% Response.contenttype = "application/vnd.ms-excel" %>
<% Response.AddHeader "Content-Disposition",...
|
by: Matt Smolic |
last post by:
Does anyone know where I can get some info on creating customer account
numbers, part numbers and such. In other words what the logic is behind
their creation. I am not looking for code, just how...
|
by: Dixie |
last post by:
I wish to add some fields to an existing table in code.
I am using the following code from rkc.
CurrentDb.Execute ("ALTER TABLE MyTable ADD MyNewField Text 25")
This works , but I need to also set...
|
by: Todd_M |
last post by:
I was wondering what anyone might suggest as "best practice" patterns for
streaming out fixed formatted text files with C#? Let's say we get our data
in a dataset table and we need to iterate over...
|
by: Mats Lycken |
last post by:
Hi,
I'm creating a CMS that I would like to be plug-in based with different
plugins handling different kinds of content.
What I really want is to be able to load/unload plugins on the fly
without...
|
by: nono909 |
last post by:
I wrote the following time class for the following assignment.i need help in completing this program pleasee.
Write a class to hold time. Time is the hour, minute and seconds. Write a constructor...
|
by: mtgrizzly52 |
last post by:
Good evening all.
I have a challenge that I have no clue on how to accomplish it. I am so close to completing a challenging database it's scary, but through beta testing we discovered a need for...
|
by: lilsugaman |
last post by:
Hi I have created an Inventory program that displays the product name, item number, how many units, and it's price and at the end displays the totals, I have to modify the program so that it will...
|
by: Andrus |
last post by:
How to create format string for decimal data type
which shows blank for zero and default format otherwize ?
I tried format string "f;f;#" but this shows f for nonzero numbers.
Andrus.
...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |