Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I have the following list. IPlist= ['209.85.238.4', '216.239.51.98', '64.233.173.198', '64.3.17.208', '64.233.173.238'] TO sort this list in ascending order, I was advised to use the following

I have the following list.

IPlist= ['209.85.238.4', '216.239.51.98', '64.233.173.198', '64.3.17.208', '64.233.173.238'] 

TO sort this list in ascending order, I was advised to use the following code snippet.

IPlist.sort (key=lambda address:list(map(int, address.split('.')))) 

It works and gives the following output.

['64. 3. 17. 208', '64. 233. 173. 198', '64. 233. 173. 238', '209. 85. 238. 4', '216. 239. 51. 98'] 

It is correct, but I am not sure I understand it. FIrst of all, what is address variable? I havent assigned address variable prior, I only have IPlist.

Example:

list1 = [1,2,3,4] final = list(map(lambda x: x*x, list1)) print(final) 

For eg, in this example I have list1 already defined aboave before mapping to a lambda function that returns the sqaure of the value. But in above function,the address is not defined so where it is getting the valurs from Iplist??

In my example, inside map, I have used the same name list1 which is already defined. If I modify the name, it wont grab the values. Similarly, the variable name of address and IPadress are different.SO how is this working?

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Fundamentals Of Database System

Authors: Elmasri Ramez And Navathe Shamkant

7th Edition

978-9332582705

More Books

Students also viewed these Databases questions

Question

Distinguish between market and financial intermediaries.

Answered: 1 week ago