+ 1

How i print not duplicate data

I am try to build python code x =[a,.....] y=[t,......] a= random x b = random y Z = a+b Print (z) x here gives me random data. #the problem is here But i need only one unique data Thank you all

30th Nov 2023, 7:17 PM
Hamza A Foji
Hamza A Foji - avatar
23 Respostas
+ 5
Hamza A Foji , not quite clear what you mean exactly. > can you please rework the sample code and the description so that we can get an idea what your issue is. thanks!
30th Nov 2023, 7:31 PM
Lothar
Lothar - avatar
+ 3
I'm confused šŸ¤” You have a loop with 20 iterations but 2 lists with 3 values each. Could you give an example of expected output please?
1st Dec 2023, 10:12 AM
Keith
Keith - avatar
+ 3
Now I'm more confused because you are saying you don't want duplicate data, but you just give an example of expected output that contains duplicate data.
1st Dec 2023, 10:39 AM
Keith
Keith - avatar
+ 3
I realize the first code meets your needs but if we wanted all combinations we could append the results in opposite order and have all 18 combinations like StuartH mentioned. https://code.sololearn.com/cI2bZvQU4SR0/?ref=app
2nd Dec 2023, 2:10 PM
Keith
Keith - avatar
+ 2
Hamza A Foji when you want to contact someone personally, just click on the @ symbol and a list of users will pop up from which you can select the one you need, then the user will receive a personal notification.
1st Dec 2023, 9:36 AM
Solo
Solo - avatar
+ 2
I think this may help you šŸ˜‰ https://code.sololearn.com/czks2wCwdotw/?ref=app
1st Dec 2023, 1:36 PM
Keith
Keith - avatar
+ 2
Keith Thank you for the help I appreciate that This is what i want exactly Great job bro
1st Dec 2023, 2:33 PM
Hamza A Foji
Hamza A Foji - avatar
+ 2
Welcome! Glad it helped šŸ‘
1st Dec 2023, 2:55 PM
Keith
Keith - avatar
+ 2
Keith i am in the first step you give me a great help bro . I think i need more practice and imagination....have a good day bro
2nd Dec 2023, 5:47 PM
Hamza A Foji
Hamza A Foji - avatar
+ 1
Thank you Keith I will try with that
30th Nov 2023, 9:23 PM
Hamza A Foji
Hamza A Foji - avatar
+ 1
If I understood your idea correctly, then this can be done without the help of "random"...šŸ˜Ž x = ['a','b','c'] y = ['x','y','z'] a = list(set(x))[0] b = list(set(y))[0] z = a+b print(z)
1st Dec 2023, 2:15 AM
Solo
Solo - avatar
+ 1
thank you solo I will try this one too I am wrong because I don't bring the code from my pc so sorry you help me with imagination.thank you
1st Dec 2023, 8:47 AM
Hamza A Foji
Hamza A Foji - avatar
+ 1
Hamza A Foji , # You don't need variables. import random print( random.choice(["happy", "sad"]), random.choice(["cat", "dog"]) ) "'" Outputs one of these phrases: sad dog sad cat happy dog happy cat """
1st Dec 2023, 11:01 AM
Rain
Rain - avatar
+ 1
Hamza A Foji , A Python set automatically removes duplicates, so what you could do is, in a loop, keep adding random combinations to a set until the set size is what you want (it won't increase when you add a duplicate) then break out of the loop and print the set. But be careful that the desired set size is not greater than the number of possible combinations, or the set will never reach that size, and the loop will keep generating duplicate combinations forever.
1st Dec 2023, 11:24 AM
Rain
Rain - avatar
+ 1
Do you want every possible combination returned or a set number of pairs? Two possibilities I can see are: 1. For a set number, enter each combination that is returned into a list. After each pair is generated, check if its in the list and if so, generate again until you get a unique value. 2. To simply output every possible combination, iterate through the lists outputting each in turn. I (or anyone else) can go into more detail on either depending on whether they are what you mean?
1st Dec 2023, 5:05 PM
StuartH
StuartH - avatar
+ 1
Thank you StuartH
1st Dec 2023, 7:52 PM
Hamza A Foji
Hamza A Foji - avatar
0
Ok i will try to grab all the code soon. Thank you
30th Nov 2023, 7:34 PM
Hamza A Foji
Hamza A Foji - avatar
0
@solo like that ok thank you bro
1st Dec 2023, 9:40 AM
Hamza A Foji
Hamza A Foji - avatar
0
Solo Keith Lothar import random import string i = 0 while i < 20: x = ["hamza", "ahmed", "safe"] y = ["cat","bird", "dog"] z =random.choice(x) r =random.choice(y) l = z+r print(l) i += 1 #i need only unique return
1st Dec 2023, 10:04 AM
Hamza A Foji
Hamza A Foji - avatar