Question

In: Computer Science

suppose i have a list in python that is [hello,yo,great,this,cool,fam] how do I get all the...

suppose i have a list in python that is [hello,yo,great,this,cool,fam]

how do I get all the possible 2 combination that I can have from this list in tuples for example output

[ {hello,hello},{hello,yo},{hello,great},....... {yo,hello},{yo,yo} and so on and son}

no packages allowed

Solutions

Expert Solution

s=[]
l=[]
l2=[]
print("Enter the size of the list :")
n=int(input())
print("Enter the elements in the list ")
for i in range(0,n):
    l.append((input()))
for i in range(0,n):
    j=0
    for j in range(0,n):
        s=[]
        s.append(l[i])
        s.append(l[j])
        l2.append(tuple(s))
print(l2)
        
    

The above program should be used when you want a user input but not when list is to be pre defined.It will asks the user to enter size and then elements of the list and then print the list of tuples exactly as defined in the program.

SCREENSHOT OF THE OUTPUT :

PYTHON CODE FOR PREDEFINED LIST.

s=[]
l=['hello','yo','great','this','cool','fam']
l2=[]

for i in range(0,len(l)):
    j=0
    for j in range(0,len(l)):
        s=[]
        s.append(l[i])
        s.append(l[j])
        l2.append(tuple(s))
print(l2)
        
    

SCREENSHOT OF THE OUTPUT :


Related Solutions

How do you calculate the velocity of a yo yo with a yo-yo that consists of...
How do you calculate the velocity of a yo yo with a yo-yo that consists of a disk (or other shape) fixed to an axle that has two strings wrapped around it. As the axle rolls off the strings, the disk and the axle fall as shown in the diagram on the right. (a) If the disk has fallen through a vertical distance of d = 30 cm and the radius of the string and axle is given by r...
hello everyone, i have this assignment to do and i dunno how to structure it as...
hello everyone, i have this assignment to do and i dunno how to structure it as i didnt have enough informations about the layout and the structure. please provide me with the structure starting from the introduction, excutive summary,...,.....,......,.......,conclusion and references. i need to fill up the paragraphs but i dunno what to layout. Assume your group comprises the Sydney City Council. In an effort to reduce inner city congestion, there is already a project to establish light rail. But...
Hello I have this error in the code, I do not know how to fix it....
Hello I have this error in the code, I do not know how to fix it. It is written in C++ using a Eclipse IDE Error: libc++abi.dylib: terminating with uncaught exception of type std::out_of_range: basic_string bus.h =========== #pragma once #include using namespace std; class Bus { private:    string BusId; // bus ID    string Manufacturer; // manufacturer of the bus    int BusCapacity; // bus capacity    int Mileage; // mileage of bus    char Status; // current status...
PYTHON-- how do i change these linkedlist methods into doublylinkedlist methods? A doublylinked list is the...
PYTHON-- how do i change these linkedlist methods into doublylinkedlist methods? A doublylinked list is the same as a linked list, except that each node has a reference to the node after it(next) and the node before it(prev). #adds item to the head of list. def add(self, item): node = Node(item, self.head) self.head = node if self.size == 0: self.tail = node self.size += 1 #appends item to tail of list def append(self, item): node = Node(item) tail = self.head...
Hello, In C++ how would I get it to ignore a percent sign in an input....
Hello, In C++ how would I get it to ignore a percent sign in an input. cout << "Enter the annual interest rate in %: "; cin >> interestRate; I want the user to input "3%" for example but having the % sign makes the program terminate. How can I get it to just read 3% (or any percent number) as just "3"
Hello I have these questions, Can I please get some assistance, I need not so long...
Hello I have these questions, Can I please get some assistance, I need not so long or short answers please How to decide what job to take. Is that a marginal decision? What is an explicit cost? What is an implicit cost? How is accounting profit calculated? How is economic profit calculated?
in verilog if i have a hex number how do i get a specific 4 bits?...
in verilog if i have a hex number how do i get a specific 4 bits? for exampe if i have a hex number 5055 how do i get the last four bits which would be 0101?
I have defined the class. Rectangle in Python. How do I define a class Canvas with...
I have defined the class. Rectangle in Python. How do I define a class Canvas with the following description: Class Canvas represents a collection of Rectangles. It has 8 methods. In addition, to the constructor (i.e. __init__ method) and two methods that override python's object methods (and make your class user friendly as suggested by the test cases), your class should contain 5 more methods: add_one_rectangle, count_same_color, total_perimeter, min_enclosing_rectangle, and common_point.
I have the following python code. I get the following message when running it using a...
I have the following python code. I get the following message when running it using a test script which I cannot send here: while textstring[iterator].isspace(): # loop until we get other than space character IndexError: string index out of range. Please find out why and correct the code. def createWords(textstrings): createdWords = [] # empty list for textstring in textstrings: # iterate through each string in trxtstrings iterator = 0 begin = iterator # new begin variable while (iterator <...
Hello everyone! I have been stuck on this problem in my python 3 coding class. Is...
Hello everyone! I have been stuck on this problem in my python 3 coding class. Is there anybody who can see what I am doing wrong? The wings are .50 cents each, If I input sour and want 20 wings it should output a 0.15 discount. I just can't get it to work but I feel like I am really close. Thank you Code: #Variables answer = str() wings = int() rate = float() discount = float() subtotal = float()...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT