Answer the question
In order to leave comments, you need to log in
How to sort and output unique hash content in Ruby?
For example, there is a hash:
list['first'] = 'BMW';
list['second'] = 'BMW';
list['third'] = 'MERCEDES';
How to sort this hash by uniqueness???
Answer the question
In order to leave comments, you need to log in
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_METHOD} !=POST
RewriteCond %{THE_REQUEST} " /(index\.php|([^?]*)\.php)"
RewriteRule ^ http://www.site.ru/%2 [R=301,L,NE]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ http://www.site.ru/$1 [R=301,L]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.site.ru/$1 [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
Just removing the slash is not the best idea, sometimes it should be closed, and most importantly, these two rules work together
https://klondike-studio.ru/standards/standartnyy-h...
Here I described in more detail
UPDATE:
list = {'first' => 'BMW', 'second' => 'BMW', 'third' = 'MERCEDES'; }
And I need:
list = {'first' => 'BMW', 'third' = 'MERCEDES'; }
If you don't care which key will be chosen, then
list.invert.invert => {"second"=>"BMW", "third"=>"MERCEDES"}
Hash[list.to_a.uniq{ |v| v.last}] => {"first"=>"BMW", "third"=>"MERCEDES"}
list['first'] = 'BMW';
list['second'] = 'BMW';
list['third'] = 'MERCEDES';
How to sort this hash by uniqueness???
h = { a: 'bmw', b: 'bmw', c: 'lada kalina' }
count = h.values.group_by(&:to_s)
h.select{ |_, v| count[v].size == 1 } => {:c=>"lada kalina"}
h.sort_by{ |_, v| count[v].size } =>
values = []
list.keys.each do |key|
if values.include?(list[key])
list.delete(key)
else
values << list[key]
end
end
a = [ "a", "a", "b", "b", "c" ]
a.uniq # => ["a", "b", "c"]
b =
b.uniq { |s| s.first } # =>
list = {first:'BMW', seccond:'BMW', third:'MERCEDES'}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question