Question

Hello can anyone help solve this please in Python the way it's asked?

Question 22 40 pts List Comprehensions Write the solution to a file named p2.py and upload it here. Comprehensions will show

h) Consider variable Ist represents list of ints [0, 1, 2,---., 19]. Write the list slice expression that results in list [16

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

a)

print([i*i for i in range(0,26)])

print(i*i for i in range(0, 26) ] ) [0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196, 225, 256, 289, 324, 361, 40

b)

print([str(i)+"**2="+str(i**2) for i in range(0,26)])

print(str(i)+ **2=+str(i**2) for i in range(0,26)]) [0**2-0, 1**2=1, 2**2-4, 3**2=9, 4**2=16, 5**2=25, 6**2=36

c)

print([(a,b,c) for a in range(1,100+1) for b in range(1,100+1) for c in range(1,100+1)  if a*a==b*b+c*c ])

print ([(а,b,с) for a in range (1,100+1) for b in range(1,100+1) for c in range(1,100+1) if a*as-b*b+с*c ]) (5, 3, 4), 5, 4,

d)

lst = ['one','seven','three','two','ten']
print([(len(i),i.upper()) for i in lst])

1st [one,seven,three,two,ten] print([(len(i),i.upper()) for i in lst]) (3, ONE) (5, SEVEN), (5, THREE), (3,

e)

names = ["Jules Verne","Alexandre Dumas","Morris Druon"]
print([n.split()[1]+","+n.split()[0] for n in names ])

f)

def unzip(seq):
    first,second = [],[]
    for t in seq:
        first.append(t[0])
        second.append(t[1])
    return tuple([first,second])

lst = [(1,"one"),(2,"two"),(3,"three")]
print(unzip(lst))

def unzip(seq): first, second for t in seq: first.append(t[0]) second.append (t [1] ) return tuple([first,second]) 1st = [(1,

g)

def concatenate(sep,*arg):#*arg is used to take arbirary number of arguments as list
    if len(arg)==1:
        return arg[0]
    else:
        s = arg[0]
        for i in range(1,len(arg)):
            s+=sep+arg[i]
    return s


print(concatenate(':',"one","two","three"))
print(concatenate(' and ',"Bonny","Clyde"))
print(concatenate('and',"single"))

def concatenate (sep, *arg) :#*arg is used to take arbirary number of arguments as list if len(arg)==1: return arg[0] else: a

h)

lst = list(range(0,20))
print(lst[16:10:-1])

list(range (0,20)) print (1st[16:10:-1]) 1st [16, 15, 14, 13, 12, 11]

i)

lst = list(range(0,20))
print(lst[16:10:-2])

list(range (0,20)) print (1st[16:10:-2]) 1st [16, 14, 12]

Add a comment
Know the answer?
Add Answer to:
Hello can anyone help solve this please in Python the way it's asked? Question 22 40 pts List Comprehensions Write...
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
  • can someone please help me write a python code for this urgently, asap Question: Write a Python function, minmp,...

    can someone please help me write a python code for this urgently, asap Question: Write a Python function, minmp, that is passed a file name and a metal alloy's formula unit structure*". The file will contain metal elements and their properties. The function will return a tuple of the element from the formula with the lowest melting point and that melting point Write a second function, molform, that will be called by the first function, to take the metal alloy's...

  • urgent help with python. can somone code this please and show output QUESTION: There are a variety of games possi...

    urgent help with python. can somone code this please and show output QUESTION: There are a variety of games possible with a deck of cards. A deck of cards has four different suits, i.e. spades (*), clubs (*), diamonds (), hearts (), and thirteen values for each suit. Now write a function that uses list comprehension to create a deck of cards. Each element in the list will be a card, which is represented by a list containing the suit...

  • C++ programming question Topic: Class 'Date' Hello everybody, can some one help me... ... Write a...

    C++ programming question Topic: Class 'Date' Hello everybody, can some one help me... ... Write a class Date with the following properties: a) Data elements of the class are day, month, year. All three data elements are defined by the Type int. b) A set and a get element function are to be provided for each data element. In Within the framework of this task, it should be assumed that the values that are passed for day and year, are...

  • Assignment 3 In this assignment, you will write a program that plot ASCII text approximations of...

    Assignment 3 In this assignment, you will write a program that plot ASCII text approximations of the Mandelbrot set. Problems Problem 1 Consider the function ?(?,?) defined as follows: ?(?,?)(?, ?) = (?2 − ?2 + ?, 2?? + ?) We define the orbit ?(?, ?) of a point (?, ?) to be an infinite list of items: ?(?, ?) = {(0, 0), ?(?,?)(0, 0), ?(?,?)(?(?,?)(0, 0)), ?(?,?)(?(?,?)(?(?,?)(0, 0))), …} In other words, the nth entry of the list ?(?,...

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
ADVERTISEMENT