Hack Forums
[Python] Simple script to Shuffle a list of emails. - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [Python] Simple script to Shuffle a list of emails. (/showthread.php?tid=5986509)



Simple script to Shuffle a list of emails. - Katе Upton - Jul 4, 2019

I have a simple request for help on coding a script to Shuffle a list of Email:Pass format.

Unsure if posting links is allowed but for reference, exactly what this site does.
Spoiler (Click to View)

PM me if you don't mind helping, can pay if needed.

Cheers lads. 👍


RE: Simple script to Shuffle a list of emails. - l0lwtf - Jul 4, 2019

I think Bash is better tool for this job:

Code
cat input.txt | shuf > output.txt

Stupid Python one-liner:

Code
cat input.txt | python -c "import sys,random; print(''.join(sorted(sys.stdin.readlines(), key=lambda k: random.random())))" > output.txt



RE: Simple script to Shuffle a list of emails. - PornFlakes - Jul 5, 2019

(Jul 4, 2019 05:44 PM)l0lwtf Wrote:  I think Bash is better tool for this job:

Code
cat input.txt | shuf > output.txt

Stupid Python one-liner:

Code
cat input.txt | python -c "import sys,random; print(''.join(sorted(sys.stdin.readlines(), key=lambda k: random.random())))" > output.txt

Good suggestion, your `.readlines()` will still take in the `\n` so you might want to do a `.read()` and `.striplines()` like in my example.


RE: Simple script to Shuffle a list of emails. - l0lwtf - Jul 5, 2019

(Jul 5, 2019 06:25 AM)PornFlakes Wrote:  your `.readlines()` will still take in the `\n` so you might want to do a `.read()` and `.striplines()` like in my example.

Nope, by using ''.join() instead of '\n'.join() I can join the elements as-is, that is, with each of them already suffixed by '\n' due to readlines(), so, I don't have to add them during the .join().

I think the only change between our 2 examples is that I print an extra newline which technically is more wrong :-)


RE: Simple script to Shuffle a list of emails. - PornFlakes - Jul 5, 2019

(Jul 5, 2019 06:36 AM)l0lwtf Wrote:  Nope, by using ''.join() instead of '\n'.join() I can join the elements as-is, that is, with each of them already suffixed by '\n' due to readlines(), so, I don't have to add them during the .join().

I think the only change between our 2 examples is that I print an extra newline which technically is more wrong :-)

The last line of the input file might not have a newline, this is why you want to clean up user input by stripping newlines and add them in later.


RE: Simple script to Shuffle a list of emails. - Katе Upton - Jul 5, 2019

(Jul 4, 2019 03:39 PM)PornFlakes Wrote:  Do you want to shuffle the positions of the email:pass lines or do you want to shuffle the emails with different passwords?


edit:

pretty sure something like this will do the trick

Code
import random

lines = open('input.txt').read().splitlines()
random.shuffle(lines)

with open('output.txt', 'w') as f:
   f.write('\n'.join(lines))

print('%s lines shuffled.' % len(lines))

Just the positions, same email:pass. This worked great, thank you very much mate.


RE: Simple script to Shuffle a list of emails. - l0lwtf - Jul 5, 2019

If you're going to use this in production I would use the Bash command. It is more performant and less code.

Code
cat input.txt | shuf > output.txt