Showing posts with label List. Show all posts
Showing posts with label List. Show all posts

Monday, June 15, 2015

Program to find two largest numbers using Python

nums = [10, 90, 80, 60, 50]
maxone = 0
maxtwo = 0
for x in nums:
if(maxone < x):
maxtwo = maxone
maxone = x

elif (maxtwo < x):
maxtwo = x

print "First two largest numbers"
print "First largest number:", maxone
print "First largest number:", maxtwo


output:

First two largest numbers
First largest number: 90
First largest number: 80

Wednesday, June 10, 2015

Sorting a list with out sort/sorted functions - Python

lst = [1,0,4,5,6,7,8,0,0,0]

print(lst)
cou = len(lst)
for i in range(cou):
    for j in range(1, cou-i):
       #descending
        """if lst[j] > lst[j-1]:
            (lst[j-1], lst[j]) = (lst[j], lst[j-1])"""
        #ascending  
        if lst[j] < lst[j-1]:
            (lst[j-1], lst[j]) = (lst[j], lst[j-1])
print(lst)

Wednesday, January 14, 2015

Selenium script to get list of values

//code to get list of values

package Ecomm_selenium;
import java.util.List;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;

//Getting list of webElements
public class Login {

                /**
                * @param args
                */
                public static void main(String[] args) {
                                // TODO Auto-generated method stub
                               
                                String site = "http://www.flipkart.com/";
                    String paths = ".//*[@id='fk-mainbody-id']/div/div[2]";                            
                    //String
                               
                                WebDriver d = new FirefoxDriver();
                                d.get(site);
                                List<WebElement> colu_vals = d.findElements(By.className("goquickly-list"));
                                java.util.Iterator<WebElement> i = colu_vals.iterator();
                                while(i.hasNext())
                                {
                                                WebElement value = i.next();
                                                System.out.println(value.getText());
                                               
                                }
                               
                               
                }

}