|
@@ -0,0 +1,50 @@
|
|
|
+from flask import Flask,request
|
|
|
+import json
|
|
|
+
|
|
|
+app = Flask(__name__)
|
|
|
+
|
|
|
[email protected]("/contains_all_chars_a", methods=['POST'])
|
|
|
+def api_contains_all_chars_a():
|
|
|
+ response={'error': None}
|
|
|
+
|
|
|
+ try:
|
|
|
+ data = request.data
|
|
|
+ response['result'] = contains_all_chars(data)
|
|
|
+ except Exception,e:
|
|
|
+ response['error'] = "Error: %s" % e.message
|
|
|
+ response['result'] = None
|
|
|
+
|
|
|
+ return json.dumps(response)
|
|
|
+
|
|
|
+
|
|
|
[email protected]("/contains_all_chars_b", methods=['POST'])
|
|
|
+def api_contains_all_chars_b():
|
|
|
+ response={'error': None}
|
|
|
+
|
|
|
+ try:
|
|
|
+ data = request.data
|
|
|
+ response['result'] = contains_all_chars_iter(data)
|
|
|
+ except Exception,e:
|
|
|
+ response['error'] = "Error: %s" % e.message
|
|
|
+ response['result'] = None
|
|
|
+
|
|
|
+ return json.dumps(response)
|
|
|
+
|
|
|
+
|
|
|
+# Python sets have an issubset function
|
|
|
+def contains_all_chars(input):
|
|
|
+ wanted_chars=set("abcdefghijklmnopqrstuvwxyz")
|
|
|
+
|
|
|
+ return wanted_chars.issubset(input)
|
|
|
+
|
|
|
+# The above is actually faster, but doesn't show any skills whatsoever
|
|
|
+# This doesn't either...
|
|
|
+def contains_all_chars_iter(input):
|
|
|
+ wanted_chars=set("abcdefghijklmnopqrstuvwxyz")
|
|
|
+
|
|
|
+ for c in input:
|
|
|
+ if c in wanted_chars:
|
|
|
+ wanted_chars.remove(c)
|
|
|
+ if len(wanted_chars) == 0:
|
|
|
+ return True
|
|
|
+ return False
|