alphanumeric

Checking if any character in a string is alphanumeric

最后都变了- 提交于 2020-06-24 08:49:33
问题 I want to check if any character in a string is alphanumeric. I wrote the following code for that and it's working fine: s = input() temp = any(i.isalnum() for i in s) print(temp) The question I have is the below code, how is it different from the above code: for i in s: if any(i.isalnum()): print(True) The for-loop iteration is still happening in the first code so why isn't it throwing an error? The second code throws: Traceback (most recent call last): File "", line 18, in TypeError: 'bool'

How do I create a random String by sampling from alphanumeric characters?

☆樱花仙子☆ 提交于 2020-02-22 06:11:27
问题 I tried to compile the following code: extern crate rand; // 0.6 use rand::Rng; fn main() { rand::thread_rng() .gen_ascii_chars() .take(10) .collect::<String>(); } but cargo build says: warning: unused import: `rand::Rng` --> src/main.rs:2:5 | 2 | use rand::Rng; | ^^^^^^^^^ | = note: #[warn(unused_imports)] on by default error[E0599]: no method named `gen_ascii_chars` found for type `rand::prelude::ThreadRng` in the current scope --> src/main.rs:6:10 | 6 | .gen_ascii_chars() | ^^^^^^^^^^^^^^^

How do I create a random String by sampling from alphanumeric characters?

只谈情不闲聊 提交于 2020-02-22 06:11:00
问题 I tried to compile the following code: extern crate rand; // 0.6 use rand::Rng; fn main() { rand::thread_rng() .gen_ascii_chars() .take(10) .collect::<String>(); } but cargo build says: warning: unused import: `rand::Rng` --> src/main.rs:2:5 | 2 | use rand::Rng; | ^^^^^^^^^ | = note: #[warn(unused_imports)] on by default error[E0599]: no method named `gen_ascii_chars` found for type `rand::prelude::ThreadRng` in the current scope --> src/main.rs:6:10 | 6 | .gen_ascii_chars() | ^^^^^^^^^^^^^^^

How do I create a random String by sampling from alphanumeric characters?

风格不统一 提交于 2020-02-22 06:09:44
问题 I tried to compile the following code: extern crate rand; // 0.6 use rand::Rng; fn main() { rand::thread_rng() .gen_ascii_chars() .take(10) .collect::<String>(); } but cargo build says: warning: unused import: `rand::Rng` --> src/main.rs:2:5 | 2 | use rand::Rng; | ^^^^^^^^^ | = note: #[warn(unused_imports)] on by default error[E0599]: no method named `gen_ascii_chars` found for type `rand::prelude::ThreadRng` in the current scope --> src/main.rs:6:10 | 6 | .gen_ascii_chars() | ^^^^^^^^^^^^^^^

How do I create a random String by sampling from alphanumeric characters?

感情迁移 提交于 2020-02-22 06:09:05
问题 I tried to compile the following code: extern crate rand; // 0.6 use rand::Rng; fn main() { rand::thread_rng() .gen_ascii_chars() .take(10) .collect::<String>(); } but cargo build says: warning: unused import: `rand::Rng` --> src/main.rs:2:5 | 2 | use rand::Rng; | ^^^^^^^^^ | = note: #[warn(unused_imports)] on by default error[E0599]: no method named `gen_ascii_chars` found for type `rand::prelude::ThreadRng` in the current scope --> src/main.rs:6:10 | 6 | .gen_ascii_chars() | ^^^^^^^^^^^^^^^

ruby alphanumeric sort not working as expected

£可爱£侵袭症+ 提交于 2020-01-30 08:55:46
问题 Given the following array: y = %w[A1 A2 B5 B12 A6 A8 B10 B3 B4 B8] => ["A1", "A2", "B5", "B12", "A6", "A8", "B10", "B3", "B4", "B8"] With the expected sorted array to be: => ["A1", "A2", "A6", "A8", "B3", "B4", "B5", "B8", "B10", "B12"] Using the following (vanilla) sort, I get: irb(main):2557:0> y.sort{|a,b| puts "%s <=> %s = %s\n" % [a, b, a <=> b]; a <=> b} A1 <=> A8 = -1 A8 <=> B8 = -1 A2 <=> A8 = -1 B5 <=> A8 = 1 B4 <=> A8 = 1 B3 <=> A8 = 1 B10 <=> A8 = 1 B12 <=> A8 = 1 A6 <=> A8 = -1 A1

ruby alphanumeric sort not working as expected

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-30 08:55:33
问题 Given the following array: y = %w[A1 A2 B5 B12 A6 A8 B10 B3 B4 B8] => ["A1", "A2", "B5", "B12", "A6", "A8", "B10", "B3", "B4", "B8"] With the expected sorted array to be: => ["A1", "A2", "A6", "A8", "B3", "B4", "B5", "B8", "B10", "B12"] Using the following (vanilla) sort, I get: irb(main):2557:0> y.sort{|a,b| puts "%s <=> %s = %s\n" % [a, b, a <=> b]; a <=> b} A1 <=> A8 = -1 A8 <=> B8 = -1 A2 <=> A8 = -1 B5 <=> A8 = 1 B4 <=> A8 = 1 B3 <=> A8 = 1 B10 <=> A8 = 1 B12 <=> A8 = 1 A6 <=> A8 = -1 A1

Sorting Alphanumeric field in SQL CE (Compact Edition) version 3.5

孤人 提交于 2020-01-21 12:52:00
问题 Sorting Alphanumeric field in SQL CE (Compact Edition) version 3.5 TreeNumber is a nvarchar field with a mix of numbers and strings for the values. I want to sort these records so that the records that contain alpha characters are at the top and the rest are sorted in numeric order. I want something similar to the following query which works in SQL Server: SELECT * FROM Tree ORDER BY (CASE WHEN TreeNumber LIKE '%[a-z]%' THEN 0 ELSE TreeNumber END), TreeNumber The above query doesn't seem to

Generating unique, random alpha numeric strings

微笑、不失礼 提交于 2020-01-14 11:36:19
问题 I am developing an application which allows users to share a link to a simple survey. For this, I want to generate unique URLs for each survey, so having a URL like: http://myapp.com/aBcDe1F I want the alpha numeric identifier part of the URL to be pseudo random and somewhat short (6-8 characters). Now, generating that is easy, but how do I ensure that they are unique but also pseudo random? Do I have to generate it, then check with a query to the database to ensure it's not been generated

Generating unique, random alpha numeric strings

北战南征 提交于 2020-01-14 11:32:04
问题 I am developing an application which allows users to share a link to a simple survey. For this, I want to generate unique URLs for each survey, so having a URL like: http://myapp.com/aBcDe1F I want the alpha numeric identifier part of the URL to be pseudo random and somewhat short (6-8 characters). Now, generating that is easy, but how do I ensure that they are unique but also pseudo random? Do I have to generate it, then check with a query to the database to ensure it's not been generated