-1
> *When using random.sample to make a password, It comes out something like this ``` ['1', '2', '3'] ``` How do I make it output something
> like this ``` 123 ``` So that I can use it to generate strings of
> passwords that includes letters numbers and symbols. Edit: I should
> probably specify that the output isnt just numbers, Its
> letters+symbols aswell*

Alright, so It has now been solved, but now i have a new issue: It comes up with this

  File "/usr/lib/python3.8/random.py", line 363, in sample
    raise ValueError("Sample larger than population or is negative")
ValueError: Sample larger than population or is negative
  • 1
    Does this answer your question? [Printing an int list in a single line python3](https://stackoverflow.com/questions/37625208/printing-an-int-list-in-a-single-line-python3) – Countour-Integral Dec 18 '20 at 19:11

2 Answers2

0
>>> A=['1','2','3']
>>> "".join(A)
'123'

join is method that combines the (string) elements of a list into one long string, with each element separated by the string used to call join.

Tyberius
  • 625
  • 2
  • 12
  • 20
0

Since random.sample is generating a list of numbers in string format, you could use a simple join() function to do the trick

    divider = ""
    YourList = divider.join(YourList) 

Update :

For generating passwords using random you could use

    import string
    import random
    bag = string.ascii_lowercase + string.ascii_uppercase + string.digits + string.punctuation

    password_length= 10
    password = ''.join([random.choice(bag) for letter_count in range(password_length)])

Place only those elements/characters in the bag which you would like your password to contain

Sahil_Angra
  • 131
  • 7