Guest User

Untitled

a guest
Nov 15th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. UnknownWord1
  2. UnknownWord2
  3. UnknownWord3
  4. UnknownWord1
  5. UnknownWord2
  6. UnknownWord3
  7.  
  8. ABCDE
  9. ACDBE
  10. EBCDA
  11. ABCDE
  12. ACDBE
  13. EBCDA
  14.  
  15. private static Random random = new Random();
  16. public static string RandomString(int length = 5)
  17. {
  18. const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  19. return new string(Enumerable.Repeat(chars, length)
  20. .Select(s => s[random.Next(s.Length)]).ToArray());
  21. }
  22.  
  23. var randoms = lines.GroupBy(x => x).Where(x => x.Count() > 1).ToDictionary(x => x.Key, x => RandomString());
  24.  
  25. var result = lines.Select(x => randoms.FirstOrDefault(f => f.Key == x).Value ?? x);
  26.  
  27. import random
  28. chars = 'ABCDEFGHIJKLMNOPQRSTUVWZYZ'
  29. lst = ['Word1', 'Word2','Word3','Word1','Word2']
  30. map = {}
  31. strset = set()
  32. result = []
  33. for line in lst:
  34. if line in map:
  35. result.append(map[line])
  36. else:
  37. rstr = ''.join([chars[random.randrange(26)] for _ in range(5)])
  38. while rstr in strset:
  39. rstr = ''.join([chars[random.randrange(26)] for _ in range(5)])
  40. map[line] = rstr
  41. strset.add(rstr)
  42. result.append(rstr)
  43.  
  44. print(result)
  45.  
  46. ['SQMHZ', 'VBEZB', 'YNTDZ', 'SQMHZ', 'VBEZB']
Add Comment
Please, Sign In to add comment