how to solve this problem using itertools.combination() ? | Sololearn: Learn to code for FREE!
+ 2

how to solve this problem using itertools.combination() ?

lst= [ ] I want to make a list of numbers from 1111 to 9999 (4 digit ) but I don't want to print the numbers which contain 0 and repeated numbers... like this numbers should be excluded : 1302 #contain zero 5830 #contain zero 1103 #repeated 1 1145 5399 #repeated 9 8555 #repeated 5 2222 #repeated 2 like this in list I don't want a number which contain repeated number.. how to do that? MY ATTEMPT: To be honest I am unable to understand the itertools.combination() from doc.python.org https://code.sololearn.com/chNcQ21GZ4h0/?ref=app

18th Nov 2020, 10:02 AM
Ratnapal Shende
Ratnapal Shende - avatar
5 Respuestas
+ 1
https://code.sololearn.com/ca621DaBw4w9/?ref=app
18th Nov 2020, 10:58 AM
Julia Shabanova
Julia Shabanova - avatar
+ 6
Ratnapal Shende , the code you posted is not complete and so not really showing a useful try. But as Julia Shabanova has allready presented a ready-to-use code (which is also my preferred version (except that it produces strings instead of integers), but just giving this code does not really help develloping people in coding ability). it's up to you whether you did a try and learn something or if you decide to copy paste. Anyway good luck!
18th Nov 2020, 11:47 AM
Lothar
Lothar - avatar
+ 5
Ratnapal Shende , please show us your attempt first. Thanks! You can use itertools.permutations(), not combinations(). it starts with: (I assumed that repeated digits are 1125 as well as 1231.) 1234 1235 1236 1237 1238 ...
18th Nov 2020, 10:24 AM
Lothar
Lothar - avatar
+ 3
Lothar edited sir
18th Nov 2020, 10:37 AM
Ratnapal Shende
Ratnapal Shende - avatar
+ 3
Lothar sir I am really interested in learning. I searched YouTube videos for it but not found any video which tells about my problem.. I tried a lot sir and finally I asked here.. I didn't copy paste sir. learned from Julia Shabanova code. his code produces strings right not integers so can i use int() to convert strings into integers ? or is their any method avaliable already in itertools ?
18th Nov 2020, 1:35 PM
Ratnapal Shende
Ratnapal Shende - avatar