Question

in python please The following statement creates a list, please rewrite it using a different way...

in python please

The following statement creates a list, please rewrite it using a different way but creating the same list.            Lst = [j for j in range (100) if j % 2 == 0]

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Dear Student,

Yes, you can write the given statement in other way as given in the following.I have also written the comments for your better understanding.

==============================================================

Program:

==============================================================

#create an empty list

Lst = []

#loo for j = 0 to 100

for j in range(100):

    #if j is divided by 2 then add the j to list

    if j % 2 == 0:

        Lst.append(j)

#print the list

print(Lst)


=============================================================

Sample Output:

Urma sharma@ubuntu:~$ python3 list.py [O, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44,

=============================================================

Kindly Check and Verify Thanks..!!!

Add a comment
Know the answer?
Add Answer to:
in python please The following statement creates a list, please rewrite it using a different way...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Need in Python! Consider the following program and expected output. Rewrite it using a for loop...

    Need in Python! Consider the following program and expected output. Rewrite it using a for loop and a conditional break statement such that it has the same output.   HINT: Stay with i as the main loop counter and let j control the break behavior.   i = 0 while i < 10 and j < 10 : j = i * 2 print(i, j) i += 1 # Output below, for reference - not part of the program! 0 0 1...

  • Need in Python! Consider the following program and expected output. Rewrite it using a for loop...

    Need in Python! Consider the following program and expected output. Rewrite it using a for loop and a conditional break statement such that it has the same output.   HINT: Stay with i as the main loop counter and let j control the break behavior.   i = 0 while i < 10 and j < 10 : j = i * 2 print(i, j) i += 1 # Output below, for reference - not part of the program! 0 0 1...

  • 1. Please write the following code in Python 3. Also please show all output(s) and share...

    1. Please write the following code in Python 3. Also please show all output(s) and share your code. Below is a for loop that works. Underneath the for loop, rewrite the problem so that it does the same thing, but using a while loop instead of a for loop. Assign the accumulated total in the while loop code to the variable sum2. Once complete, sum2 should equal sum1. sum1 = 0 lst = [65, 78, 21, 33] for x in...

  • python Make another code block that creates a list using range( ) with 8 values starting...

    python Make another code block that creates a list using range( ) with 8 values starting with 1. print out your list Create a set from each of the three lists. Find the elements in common between the three sets.

  • I need to rewrite this code without using lambda function using python. def three_x_y_at_one(x): result =...

    I need to rewrite this code without using lambda function using python. def three_x_y_at_one(x): result = (3 * x *1) return result three_x_y_at_one(3) # 9 zero_to_four = list(range(0, 5)) def y_values_for_at_one(x_values): return list(map(lambda x : three_x_y_at_one(x), x_values)) -------> this is the function that I need to rewrite without using a lambda function . y_values_for_at_one(zero_to_four) # [0, 3, 6, 9, 12] Thanks

  • please rewrite code (IN PYTHON 3.7.4) using a while loop.   >>> population = 300000 >>> for...

    please rewrite code (IN PYTHON 3.7.4) using a while loop.   >>> population = 300000 >>> for year in range (2014, 2019): print("{0:10d} {1:10d}".format(year, int(population))) population = 1.03 * population 2014 2015 2016 2017 2018 300000 309000 318270 327818 337652

  • In PYTHON Write a program that # 1) Creates a list of 25 numbers that are...

    In PYTHON Write a program that # 1) Creates a list of 25 numbers that are all different # 2) Takes a user-input number and then determines which number in the list is closest to the user-input number.

  • USE IDLE PLATFORM FOR PYTHON PLEASE Write a Python program that creates a list that contains...

    USE IDLE PLATFORM FOR PYTHON PLEASE Write a Python program that creates a list that contains players of your favorite teams. The program then should ask the user to enter the name of a player. If the player is in your list, display a message indicating that the player is in the team. Otherwise, the program should display a message stating that the player isn't on the team.

  • Consider the following Python program, where x is assumed to be a list of integers. def...

    Consider the following Python program, where x is assumed to be a list of integers. def mystery_func(x): n = len(x) for i in range(n - 1): for j in range(i + 1, n): if x[j] - x[i] < j - i: return False return True 3a. In plain English, describe what it accomplishes (i.e., the relationship between input and output, not how the code works). 3b. Analyze the running time and express it with big O. 3c. Rewrite this function...

  • Python recursive function: Given an ordered list L. A permutation of L is a rearrangement of...

    Python recursive function: Given an ordered list L. A permutation of L is a rearrangement of its elements in some order. For example (1,3, 2) and (3, 2, 1) are two different permutations of L=(1,2,3). Implement the following function: def permutations (lst, low, high) The function is given a list 1st of integers, and two indices: low and high (lows high), which indicate the range of indices that need to be considered The function should return a list containing all...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT