473,407 Members | 2,326 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

extend list according to its elements

51
i'm looking for a way to extend a list of 2 elements that represent boundaries, to the entire range.


for example: input list = [1 ,5,10,15]
output list would be = [1, 2, 3, 4 ,5 , 10 , 11 , 12 ,13 ,14 ,15]


i can make it using the following semi-pseudo code, but perhaps there is an easier way, more elegant...

Expand|Select|Wrap|Line Numbers
  1. $i = 0; 
  2. while $i != length(list) 
  3.     for ($j = list($i); j++; j<list($i+1)) {
  4.           push(@out_list,$j); 
  5.       }; 
  6.      $i += 2; 
  7. };
Apr 22 '08 #1
1 1081
nithinpes
410 Expert 256MB
i'm looking for a way to extend a list of 2 elements that represent boundaries, to the entire range.


for example: input list = [1 ,5,10,15]
output list would be = [1, 2, 3, 4 ,5 , 10 , 11 , 12 ,13 ,14 ,15]


i can make it using the following semi-pseudo code, but perhaps there is an easier way, more elegant...

$i = 0;
while $i != length(list)
for ($j = list($i); j++; j<list($i+1)) {
push(@out_list,$j);
};
$i += 2;
};
Though logic remains the same, you may reduce the number of lines of code by using this:
Expand|Select|Wrap|Line Numbers
  1. for($i=0;$i<@list;$i+=2) {
  2. push @out_list,($list[$i]..$list[$i+1]);
  3. }
  4.  
Apr 22 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Matthew Wilson | last post by:
I have a list of very simple circle objects: class Circle: def __init__(self, x,y,r): self.center =(x,y) self.r = r I want to write a function that accepts a list of circle objects and then...
33
by: Jim Cobban | last post by:
I cannot get Netscape 4.79 to properly display the ordered list in the following fragment. <P>Get a specific portion of the date. Depending upon the value of index: <ol start=0> <li>complete...
12
by: Jeff | last post by:
Hello, I'm finishing a speech recognition jukebox (http://intelligentjukebox.com/) I have a very basic template question. I can't find any good examples of what I want to do. I could write...
6
by: Arne Claus | last post by:
Hi If've just read, that remove() on a list does not actually remove the elements, but places them at the end of the list (according to TC++STL by Josuttis). It also says, that remove returns a...
2
by: greenflame | last post by:
I am trying to reorder elements of a list and I am stuck as to what might be the best way to approach this. I have a (main) list of elements and another (ordering) list (which is may shorter, but...
6
by: Amit Bhatia | last post by:
Hi, I am not sure if this belongs to this group. Anyway, my question is as follows: I have a list (STL list) whose elements are pairs of integers (STL pairs, say objects of class T). When I create...
0
by: Amar | last post by:
Hi, I have a generic list with a some objects of a particular class in it. I have implemented a IComparer for the the class and pass it to the List. The list.sort method works fine when the value...
3
by: Tony Johansson | last post by:
Hello! Sorry for opening up this task again. I want to fully understand this List that is return from CollectionBase. According to you is List in CollectionBase implemented something like...
11
by: Juha Nieminen | last post by:
Assume we have this: std::list<Typelist1(10, 1), list2(20, 2); std::list<Type>::iterator iter = list1.end(); list1.swap(list2); What happens here, according to the standard? 1) 'iter'...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
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...
0
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...
0
tracyyun
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.