473,465 Members | 1,921 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How to reverse a list for the purpose of finding the previous item with a condition ?

56 New Member
Dear friends,
I try to find the forward and backward content of a play list . The main item is identified using <h1> tag ...
I wrote a code for forward item which works fine as below:

Expand|Select|Wrap|Line Numbers
  1.     if(direction == "forward"):
  2.     counter = 0
  3.     for i in range(self.pos_indice,len(self.indice)):
  4.         if(self.indice[i+1].tagName == "h1"):
  5.            break
  6.         else:
  7.            counter = counter+1
  8.     return counter+1
  9.  
  10.  

but in reverse my code fails as shown below:

Expand|Select|Wrap|Line Numbers
  1.  
  2. if(direction == "backword"):
  3.     rev_counter = self.pos_indice
  4.     for j in range(self.pos_indice,0,-1):
  5.         if(self.indice[j+1].tagName == "h1"):
  6.            break
  7.         else:
  8.            rev_counter = rev_counter + 1
  9.     return rev_counter+1
  10.  
Please advise with a solution fast

Thanks
Anes
Jan 25 '16 #1
2 1335
Luk3r
300 Contributor
Python has a built-in reversed() function which can be used in a For loop.
Jan 25 '16 #2
amskape
56 New Member
Dear Luk3r,
I used following code for purpose and feel works fine 90% !!

Expand|Select|Wrap|Line Numbers
  1.  
  2.     if(direction == "backword"):
  3.     rev_counter = 0
  4.     for j in range(self.pos_indice,-1,-1):
  5.  
  6.         if(self.indice[j-1].tagName == "h1"):
  7.            break
  8.         else:
  9.            rev_counter = rev_counter + 1
  10.     return rev_counter+1
  11.  
Please advise any further modifications....

Thanks
Anes
Jan 26 '16 #3

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

Similar topics

2
by: Coffee guy | last post by:
I need to locate an item in ListView, quickly. I have a listview with items, for each I added a unique "Tag" property. Is there a simple way to rapidly search through these items to find based on...
2
by: farseer | last post by:
Hi, I have a combobox who's data source i set to an array of objects (call it MyObject). these objects have get properties: key, value, descr. i set ValueMember to "key", DisplayMember to...
4
by: Chris | last post by:
Using: DataGrid1_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.ItemCommand is there a way to find a specific item in the...
3
by: venky | last post by:
Hi, I have a question regarding page navigation. See i have a page called page1.aspx and page2.aspx. On some event in the both the pages the page get transfered to page3.aspx using...
4
by: Dica | last post by:
i've got a dropdown list with various options added to it. i want to add a button that allows the user to "Add New Option' which should create a blank row on the dropdown list and allow the user to...
7
by: Miguel E. | last post by:
Hi, I've been (self) studying Python for the past two months and I have had no background in OOP whatsoever. I was able to write an interactive program that randomly selects an item from a...
1
by: plmanikandan | last post by:
Hi, I have a listview with items,subitems.I tems and subitems are added as below listView1.View = View.Details; listView1.Columns.Add("Column 1", 100,HorizontalAlignment.Center);...
0
by: Carlos | last post by:
Hi all, I have a hyperlink pointing to a page that contains a dropdownlist. This dropdown is loaded using a datatable when the page is loaded. However, I would like the hyperlink to point to the...
1
by: bobbly | last post by:
I am working on a Page that will reference data from a query. My query shows all of the companies I work with, about 1800 in total. I am creating a page where the user can select the customer from a...
0
by: simi sankar | last post by:
I have 2 combobox, when I select a perticular item from 1st combobox it will display the result but when select another it will display item with previous item what will i do?
0
marktang
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,...
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...
1
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.