I have this code
JavaScript
x
17
17
1
import itertools
2
import random
3
4
def gen_reset_key():
5
key = random.randint(100, 199)
6
return key
7
8
key_combinations = list(itertools.combinations(str(gen_reset_key()), 2))
9
10
key_one = key_combinations[0]
11
key_two = key_combinations[1]
12
key_three = key_combinations[2]
13
14
print("Key one is: {}".format(key_one))
15
print("Key two is: {}".format(key_two))
16
print("Key three is: {}".format(key_three))
17
The output is:
JavaScript
1
4
1
Key one is: ('1', '9')
2
Key two is: ('1', '9')
3
Key three is: ('9', '9')
4
I want to remove the brackets and speech marks from the output. How can I achieve that?
so that my output would be:
JavaScript
1
4
1
Key one is 19
2
Key two is 19
3
Key three is 99
4
Advertisement
Answer
You can accomplish this in the following way (without using str.join
):
JavaScript
1
4
1
print('Key one is: {}{}'.format(*key_one))
2
print('Key two is: {}{}'.format(*key_two))
3
print('Key three is: {}{}'.format(*key_three))
4
This should have the added benefit of avoiding the creation of intermediate strings in the join
.