✕

Find the best tutors and institutes for BTech Tuition

Find Best BTech Tuition

✕

Search for topics

Follow 6

24 Answers

public class DemoApplication { public static void main(String args) { //SpringApplication.run(DemoApplication.class, args); List<Order> list=new ArrayList(); list.add(new Order("34587", 163.8)); list.add(new Order("98762", 284.0)); list.add(new Order("77226", 98.85)); list.add(new Order("88112",... read more

**public** **class** DemoApplication {

**public** **static** **void** main(String[] args) {

//SpringApplication.run(DemoApplication.class, args);

List<Order> list=**new** ArrayList();

list.add(**new** Order("34587", 163.8));

list.add(**new** Order("98762", 284.0));

list.add(**new** Order("77226", 98.85));

list.add(**new** Order("88112", 74.97));

System.** out**.println("Before Processing List orders :: "+list);

**int** index=-1;

**for**(Order order: list) {

index++;

**if**(order.getPrice()<100) {

order.setPrice(order.getPrice()+10);

list.set(index, order);

}

}

System.** out**.println("After processing List orders :: "+list);

}

}

**class** Order{

**private** String orderNo;

**private** **double** price;

**public** Order(String orderNo, **double** price) {

**super**();

**this**.orderNo = orderNo;

**this**.price = price;

}

**public** **void** setOrderNo(String orderNo){

**this**.orderNo=orderNo;

}

**public** String getOrderNo(){

**return** orderNo;

}

**public** **void** setPrice(**double** price){

**this**.price=price;

}

**public** **double** getPrice(){

**return** price;

}

@Override

**public** String toString() {

**return** "Order [orderNo=" + orderNo + ", price=" + price + "]";

}

}

read less 0

Comments

Pythonized my previous answer: OUTPUT = oL = oL.extend()OUTPUT = oLprint(OUTPUT) read more

Pythonized my previous answer:

OUTPUT = [ ('34587',163.8),('98762',284.0),('77226',98.85),('88112',74.97) ]

oL = []

oL.extend([(id, price + 10) for id, price in OUTPUT if price < 100.00 or\

oL.append((id, price))])

OUTPUT = oL

print(OUTPUT)

0

Comments

Hello Anurag, As per your question, Input:- a list of tuples with two values (order-number: string, total-order-cost: float) each Output:- the updated list of tuples. Condition: When b < 100, b = b + 10 where b: total-order-cost (product of the price per items and the quantity) for every tuple of... read more

Hello Anurag,

As per your question,

**Input**:- a list of tuples with two values (order-number: string, total-order-cost: float) each

**Output**:- the updated list of tuples.

**Condition**: When b < 100, b = b + 10 where b: total-order-cost (product of the price per items and the quantity) for every tuple of (a, b) in the input list.

**Program**:

**1) With regular for-loop**:

# You might use list(input()) to read list from user input.

inputList = [('34587',163.8),('98762',284.0),('77226',98.85),('88112',74.97)]

outputList = []

for _tuple in inputList:

if (_tuple[1] < 100):

outputList.append((_tuple[0], _tuple[1]+10))

else:

outputList.append((_tuple[0],_tuple[1]))

print('Updated List:',outputList)

PS: Since tuples are immutable (cannot change it's value further) in python, we used one more list instead of replacing the given input list itself.

**2) With list-comprehension**:-

inputList = [('34587',163.8),('98762',284.0),('77226',98.85),('88112',74.97)]

def getUpdatedList(inputList):

return [(ele[0], ele[1]+10) if (ele[1]) < 100 else (ele[0], ele[1]) for ele in inputList]

outputList = getUpdatedList(inputTuple)

print(outputList)

Or simply,

print([(ele[0], ele[1]+10) if (ele[1]) < 100 else (ele[0], ele[1]) for ele in inputList])

Feel free to ask me any further questions. Happy Coding!!!

read less

0

Comments

Hello Anurag, As per your question, Input:- a list of tuples with two values (order-number: string, total-order-cost: float) each Output:- the updated list of tuples. Condition: When b < 100, b = b + 10 where b: total-order-cost (product of the price per items and the quantity) for every tuple of... read more

Hello Anurag,

As per your question,

**Input**:- a list of tuples with two values (order-number: string, total-order-cost: float) each

**Output**:- the updated list of tuples.

**Condition**: When b < 100, b = b + 10 where b: total-order-cost (product of the price per items and the quantity) for every tuple of (a, b) in the input list.

**Program**:

**1) With regular for-loop**:

# You might use list(input()) to read list from user input.

inputList = [('34587',163.8),('98762',284.0),('77226',98.85),('88112',74.97)]

outputList = []

for _tuple in inputList:

if (_tuple[1] < 100):

outputList.append((_tuple[0], _tuple[1]+10))

else:

outputList.append((_tuple[0],_tuple[1]))

print('Updated List:',outputList)

PS: Since tuples are immutable (cannot change it's value further) in python, we used one more list instead of replacing the given input list itself.

**2) With list-comprehension**:-

inputList = [('34587',163.8),('98762',284.0),('77226',98.85),('88112',74.97)]

def getUpdatedList(inputList):

return [(ele[0], ele[1]+10) if (ele[1]) < 100 else (ele[0], ele[1]) for ele in inputList]

outputList = getUpdatedList(inputTuple)

print(outputList)

Or simply,

print([(ele[0], ele[1]+10) if (ele[1]) < 100 else (ele[0], ele[1]) for ele in inputList])

Feel free to ask me any further questions. Happy Coding!!!

read less

0

Comments

Hello Anurag, As per your query, Input:- a list of tuples with two values (order-number: string, total-order-cost: float) each Output:- the updated list of tuples. Condition: When b < 100, b = b + 10 where b: total-order-cost (product of the price per items and the quantity) for every tuple of (a,... read more

Hello Anurag,

As per your query,

**Input**:- a list of tuples with two values (order-number: string, total-order-cost: float) each

**Output**:- the updated list of tuples.

**Condition**: When b < 100, b = b + 10 where b: total-order-cost (product of the price per items and the quantity) for every tuple of (a, b) in the input list.

**Program**:

**1) With regular for-loop**:

# You might use list(input()) to read list from user input.

inputList = [('34587',163.8),('98762',284.0),('77226',98.85),('88112',74.97)]

outputList = []

for _tuple in inputList:

if (_tuple[1] < 100):

outputList.append((_tuple[0], _tuple[1]+10))

else:

outputList.append((_tuple[0],_tuple[1]))

print('Updated List:',outputList)

PS: Since tuples are immutable (cannot change it's value further) in python, we used one more list instead of replacing the given input list itself.

**2) With list-comprehension**:-

inputList = [('34587',163.8),('98762',284.0),('77226',98.85),('88112',74.97)]

def getUpdatedList(inputList):

return [(ele[0], ele[1]+10) if (ele[1]) < 100 else (ele[0], ele[1]) for ele in inputList]

outputList = getUpdatedList(inputTuple)

print(outputList)

Or simply,

print([(ele[0], ele[1]+10) if (ele[1]) < 100 else (ele[0], ele[1]) for ele in inputList])

Feel free to ask me any further questions. Happy Coding!!!

read less

0

Comments

Hello Anurag, As per your query, Input:- a list of tuples with two values (order-number: string, total-order-cost: float) each Output:- the updated list of tuples. Condition: When b < 100, b = b + 10 where b: total-order-cost (product of the price per items and the quantity) for every tuple of (a,... read more

Hello Anurag,

As per your query,

**Input**:- a list of tuples with two values (order-number: string, total-order-cost: float) each

**Output**:- the updated list of tuples.

**Condition**: When b < 100, b = b + 10 where b: total-order-cost (product of the price per items and the quantity) for every tuple of (a, b) in the input list.

**Program**:

**1) With regular for-loop**:

# You might use list(input()) to read list from user input.

inputList = [('34587',163.8),('98762',284.0),('77226',98.85),('88112',74.97)]

outputList = []

for _tuple in inputList:

if (_tuple[1] < 100):

outputList.append((_tuple[0], _tuple[1]+10))

else:

outputList.append((_tuple[0],_tuple[1]))

print('Updated List:',outputList)

**2) With list-comprehension**:-

inputList = [('34587',163.8),('98762',284.0),('77226',98.85),('88112',74.97)]

def getUpdatedList(inputList):

return [(ele[0], ele[1]+10) if (ele[1]) < 100 else (ele[0], ele[1]) for ele in inputList]

outputList = getUpdatedList(inputTuple)

print(outputList)

Or simply,

print([(ele[0], ele[1]+10) if (ele[1]) < 100 else (ele[0], ele[1]) for ele in inputList])

Feel free to ask me any further questions. Happy Coding!!!

read less

0

Comments

# Python code to sort a list of tuples # according to given key. # get the last key. def last(n): return n # function to sort the tuple def sort(tuples): # We pass used defined function last # as a parameter. return sorted(tuples, key = last) # driver code a = m = 2print("Sorted:"), print(sort(a))... read more

# Python code to sort a list of tuples

# according to given key.

# get the last key.

def last(n):

return n[m]

# function to sort the tuple

def sort(tuples):

# We pass used defined function last

# as a parameter.

return sorted(tuples, key = last)

# driver code

a = [(23, 45, 20), (25, 44, 39), (89, 40, 23)]

m = 2

print("Sorted:"),

print(sort(a))

0

Comments

Input:-a list of tuples with two values (order-number: string, total-order-cost: float) each Output:- the updated list of tuples. Condition: When b < 100, b = b + 10 where b: total-order-cost (product of the price per items and the quantity) for every tuple of (a, b) in the input list. Program: 1)... read more

Input:-a list of tuples with two values (order-number: string, total-order-cost: float) each Output:- the updated list of tuples.

Condition: When b < 100, b = b + 10 where b: total-order-cost (product of the price per items and the quantity) for every tuple of (a, b) in the input list. Program: 1) With regular for-loop: # You might use list(input()) to read list from user input. inputList = [('34587',163.8),('98762',284.0),('77226',98.85),('88112',74.97)] outputList = [] for _tuple in inputList: if (_tuple[1] < 100): outputList.append((_tuple[0], _tuple[1]+10)) else: outputList.append((_tuple[0],_tuple[1])) print('Updated List:',outputList)

2) With list-comprehension:- inputList = [('34587',163.8),('98762',284.0),('77226',98.85),('88112',74.97)] def getUpdatedList(inputList): return [(ele[0], ele[1]+10) if (ele[1]) < 100 else (ele[0], ele[1]) for ele in inputList] outputList = getUpdatedList(inputTuple) print(outputList) Or simply, print([(ele[0], ele[1]+10) if (ele[1]) < 100 else (ele[0], ele[1]) for ele in inputList])

Feel free to ask me any further questions. enjoy coding.

read less 0

Comments

View 22 more Answers

Now ask question in any of the 1000+ Categories, and get Answers from Tutors and Trainers on UrbanPro.com

Ask a QuestionRecommended Articles

Tuitions for Professional courses - Does...

MBA, Medicine and engineering are the three main professional courses in India. Engineering is still one of the highly sorted after professional courses in the under graduate level, while MBA is favoured as a preferred post graduate course. To shine in these courses, one needs to work and study hard. Engineering as a...

Finding Tuitions for Bachelor of Engineering...

According to a recent survey conducted by the NCAER (National Council of Advanced Economic Research), engineering is the most sought after course in India. Some engineering courses are offered as BE or Bachelor of Engineering while some as Bachelor in Technology or B.Tech. Since engineering is a professional course, the...

Science, Arts Or Commerce - Which One To Go For?

Once over with the tenth board exams, a heavy percentage of students remain confused between the three academic streams they have to choose from - science, arts or commerce. Some are confident enough to take a call on this much in advance. But there is no worry if as a student you take time to make choice between - science,...

How To Choose The Right School For Children?

When it comes deciding the right school for children, parents definitely try to be accurate. Yet the competitive academic industry offers too many options when it comes to school for children and there begins the confusion. With new schools coming up, parents get utterly confused which school will be the best for their...

Looking for BTech Tuition ?

Find best BTech Tuition in your locality on UrbanPro.

Are you a Tutor or Training Institute?

Join UrbanPro Today to find students near you X ### Looking for BTech Tuition Classes?

Find best tutors for BTech Tuition Classes by posting a requirement.

- Post a learning requirement
- Get customized responses
- Compare and select the best

Find best BTech Tuition Classes in your locality on UrbanPro

Post your learning requirement