Computer Science, asked by thivakar52, 5 months ago

Find the output
x=[10,20,30,40,50,60]
y=x
y[3]=99
print(x)
Your answer​

Answers

Answered by devidkumar40
1

Answer:

We learned in the previous chapter "Lambda Operator, Filter, Reduce and Map" that Guido van Rossum prefers list comprehensions to constructs using map, filter, reduce and lambda. In this chapter we will cover the essentials about list comprehensions.

List comprehensions were added with Python 2.0. Essentially, it is Python's way of implementing a well-known notation for sets as used by mathematicians. In mathematics the square numbers of the natural numbers are, for example, created by { x2 | x ∈ ℕ } or the set of complex integers { (x,y) | x ∈ ℤ ∧ y ∈ ℤ }.

List comprehension is an elegant way to define and create lists in Python. These lists have often the qualities of sets, but are not necessarily sets.

List comprehension is a complete substitute for the lambda function as well as the functions map(), filter() and reduce(). For most people the syntax of list comprehension is easier to be grasped.

Examples

In the chapter on lambda and map() we designed a map() function to convert Celsius values into Fahrenheit and vice versa. It looks like this with list comprehension:

Celsius = [39.2, 36.5, 37.3, 37.8]

Fahrenheit = [ ((float(9)/5)*x + 32) for x in Celsius ]

print(Fahrenheit)

[102.56, 97.7, 99.14, 100.03999999999999]

Similar questions