-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcodewars_functions_.py
3170 lines (2011 loc) · 65.6 KB
/
codewars_functions_.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
def close_compare(a, b, margin=0):
# return 0 if not abs(a - b) < margin and not a > b else (1 if not abs(a - b) > margin and not a > b else -1)
return -1 if a < b and abs(a - b) > margin else (1 if a > b else 0)
# print(close_compare(3, 5, 3))
# print(close_compare(3, 5, 0))
# print(close_compare(2, 5, 3))
# print(close_compare(5, 5, 3))
# print(close_compare(4, 5, ))
# print(close_compare(5, 5, ))
# print(close_compare(6, 5, ))
# test.assert_equals(close_compare(4, 5), -1)
# test.assert_equals(close_compare(5, 5), 0)
# test.assert_equals(close_compare(6, 5), 1
# test.assert_equals(close_compare(2, 5, 3), 0)
# test.assert_equals(close_compare(5, 5, 3), 0)
# test.assert_equals(close_compare(8, 5, 3), 0)
# test.assert_equals(close_compare(8.1, 5, 3), 1)
# test.assert_equals(close_compare(1.99, 5, 3), -1)
def to_jaden_case(string):
return ' '.join(word.capitalize() for word in string.split())
print(to_jaden_case('Hello world my new home is far from here'))
def to_jaden_case_1(string):
return [word.capitalize() for word in string.split()]
# print(to_jaden_case_1('Hello world my new home is far from here'))
def get_count(sentence):
t = []
for word in sentence:
if 'a' in word:
t.append('a')
if 'e' in word:
t.append('e')
if 'i' in word:
t.append('i')
if 'o' in word:
t.append('o')
if 'u' in word:
t.append('u')
return len(t)
print(get_count('Hello world my new home is far from here'))
def get_count_2(sentence):
t = []
for word in sentence:
for vowel in 'aeiou':
if vowel in word:
t.append(vowel)
return len(t)
def get_count_3(sentence):
t = [vowel for word in sentence for vowel in 'aeiou' if vowel in word]
return len(t)
def past(h, m, s):
return (h * 3600000) + (m * 60000) + (s * 1000)
# print(past(0, 1, 1))
def get_middle(s):
return s[len(s) // 2 - 1:len(s) // 2 + 1] if not len(s) % 2 else s[len(s) // 2]
print(get_middle('test'))
print(get_middle('testing'))
def abbrev_name(name):
return '.'.join(word[0].capitalize() for word in name.split())
print(abbrev_name('Sam Harris'))
def descending_order(num):
return int(''.join(sorted(str(num), reverse=True)))
print(descending_order(42145))
def DNA_strand(dna):
new_l = []
for letter in dna:
if letter == 'A':
new_l.append('T')
elif letter == 'T':
new_l.append('A')
elif letter == 'C':
new_l.append('G')
elif letter == 'G':
new_l.append('C')
return ''.join(new_l)
def DNA_strand_1(dna):
# return ''.join(['T' if letter == 'A' else 'A' if letter == 'T' else 'G' if letter == 'C' else 'C' for letter in dna])
return ''.join(
['T' if letter == 'A' else 'A' if letter == 'T' else 'G' if letter == 'C' else 'G' for letter in dna])
# print(DNA_strand("AAAA"))
# print(DNA_strand("ATTGC"))
# print(DNA_strand_1("ATTGC"))
# print(DNA_strand("GTAT"))
def basic_op_2(operator, value1, value2):
if operator == '+':
return value1 + value2
elif operator == '-':
return value1 - value2
elif operator == '*':
return value1 * value2
elif operator == '/':
return value1 / value2
else:
raise ValueError("Nieznany operator")
def basic_op(operator, value1, value2):
return (
value1 + value2 if operator == '+' else
value1 - value2 if operator == '-' else
value1 * value2 if operator == '*' else
value1 / value2 if operator == '/' else None
)
def basic_op_3(operator, value1, value2):
return eval(f'{value1} {operator} {value2}')
print(basic_op_3('-', 5, 7))
def contains_all_alphabet_letters(s):
alphabet_set = set("abcdefghijklmnopqrstuvwxyz")
s_set = set(s.lower()) # Zakładam, że wielkość liter nie ma znaczenia
return all(letter in s_set for letter in alphabet_set)
def is_pangram(s):
return True if all(letter in set(s.lower()) for letter in set("abcdefghijklmnopqrstuvwxyz")) else False
# print(is_pangram("The quick brown fox jumps over the lazy dog"))
def has_duplicate_letters_1(s):
for letter in s:
if s.count(letter) > 1:
return True
return False
def has_duplicate_letters(string):
return all(string.lower().count(letter) <= 1 for letter in string)
def is_isogram(string):
return len(set(string.lower())) == len(string)
print(has_duplicate_letters("Dermatoglyphics"))
print(has_duplicate_letters("moose"))
print(has_duplicate_letters("aba"))
print(has_duplicate_letters(""))
def disemvowel(string_):
# vowels = "AEIOUaeiou"
return ''.join(char for char in string_ if char not in "AEIOUaeiou")
print(disemvowel("This website is for losers LOL!"))
def some_f(anystr):
return ' '.join([word[::3] for word in anystr.split()])
print(some_f("Ala ma kota a kot ma ale123"))
def some_f_1(anyint):
return int(str(anyint)[1:-1])
print(some_f_1(12398765455))
def count_by(x, n):
new_l = []
for i in range(x, x * n + 1, x):
new_l.append(i)
return new_l
print(count_by(2, 5))
def count_by_2(x, n):
return [x for x in range(x, x * n + 1, x)]
print(count_by_2(2, 5))
def get_sum(a, b):
return sum([num for num in range(a, b + 1)])
print(get_sum(-1, 2))
def get_sum(a, b):
return sum(range(min(a, b), max(a, b) + 1))
def better_than_average(class_points, your_points):
return True if len(class_points) / sum(class_points) < your_points else False
def square_sum(numbers):
return sum([num ** 2 for num in numbers])
print(square_sum([0, 3, 4, 5]))
def find_it(seq):
return [num for num in seq if seq.count(num) % 2][0]
print(find_it([20, 1, -1, 2, -2, 3, 3, 5, 5, 1, 2, 4, 20, 4, -1, -2, 5]))
print(find_it([1, 1, 2, -2, 5, 2, 4, 4, -1, -2, 5]))
def sum_two_smallest_numbers(numbers):
sorted_list = sorted(numbers)
return sorted_list[0] + sorted_list[1]
print(sum_two_smallest_numbers([5, 8, 12, 18, 22]))
def maps(a):
# return list(set([num * 2 for num in a]))
return [num * 2 for num in set(a)]
print(maps([1, 1, 2, -2, 5, 2, 4, 4, -1, -2, 5]))
def lovefunc(flower1, flower2):
return (flower1 % 2 == 1 and flower2 % 2 == 0) or (flower1 % 2 == 0 and flower2 % 2 == 1)
print(lovefunc(2, 2))
print(lovefunc(0, 2))
print(lovefunc(168, 328))
def build_tower(n):
tower = []
for i in range(n):
spaces = ' ' * (n - i - 1)
stars = '*' * (2 * i + 1)
tower.append(spaces + stars + spaces)
return tower
def bulid_tower_1(n):
return [' ' * (n - i - 1) + '*' * (2 * i + 1) + ' ' * (n - i - 1) for i in range(n)]
print(bulid_tower_1(3))
def series_sum(n):
if n == 0:
return "0.00"
total = 0.0
denominator = 1
for _ in range(n):
total += 1 / denominator
denominator += 3
return "{:.2f}".format(total)
print(series_sum(1))
def open_or_senior(data):
return ["Senior" if i >= 55 and k > 7 else "Open" for i, k in data]
def digitize(n):
return [int(i) for i in str(n)][::-1]
def leo(oscar):
if oscar == 88:
return "Leo finally won the oscar! Leo is happy"
elif oscar == 86:
return "Not even for Wolf of wallstreet?!"
elif not (oscar == 88 or oscar == 86) and oscar < 88:
return "When will you give Leo an Oscar?"
elif oscar > 88:
return "Leo got one already!"
# print(leo(100))
def pipe_fix(nums):
return [num for num in range(nums[0], nums[-1] + 1)]
print(pipe_fix([1, 2, 3, 4, 5, 9]))
def sum_mix(arr):
return sum(int(i) for i in arr)
# print(sum_mix([9, 3, '7', '3']))
def hero(bullets, dragons):
return dragons * 2 <= bullets
# print(hero(100, 40))
def cannons_ready(gunners):
return "Fire!" if all(response == 'aye' for response in gunners.values()) else "Shiver me timbers!"
def shorten_to_date(long_date):
return " ".join(long_date.split(", ")[:-1])
def correct(s):
change_s = {'0': 'O', '1': 'I', '5': 'S'}
return ''.join(change_s.get(char, char) for char in s)
def correct_1(string):
return string.replace('1', 'I').replace('0', 'O').replace('5', 'S')
def reverse(st):
# Your Code Here
return ' '.join(st.split()[::-1])
def correct_polish_letters(st):
new_dict = {'ą': 'a',
'ć': 'c',
'ę': 'e',
'ł': 'l',
'ń': 'n',
'ó': 'o',
'ś': 's',
'ź': 'z',
'ż': 'z'}
return ''.join(new_dict[letter] if letter in new_dict else letter for letter in st)
print(correct_polish_letters('Władek ślusarz'))
# 01
import statistics
def create_list(i, j):
return [i, j] * 4
print(create_list(1, 2))
print(create_list(True, False))
# 02
couples_dict = {
'Alice': 28,
'Bob': 30,
'Charlie': 25,
'Diana': 22,
'Eve': 35,
'Frank': 32
}
def list_keys(d):
temp = []
for key in d:
temp.append(key)
# return temp
return list(d.keys())
# return d.values()
# return d.items()
print(list_keys(couples_dict))
# 03
word_list = ['cat', 'banana', 'carrot', 'dog', 'elephant']
def find_short_words(words):
temp = []
for word in words:
if len(word) < 5:
temp.append(word)
return temp
l = find_short_words(word_list)
print(l)
# 04
a_list = [1, 2, 3, 4, 5]
def suma(numbers):
result = 0
for number in numbers:
result += number
return result
print(suma(a_list))
# 05
def suma_2(numbers):
result = numbers[0]
for number in numbers[1:]:
result += number
return result
print(suma_2(a_list))
# 06
def mean(numbers):
return statistics.mean(numbers)
print(mean(a_list))
# 07
def mean_2(numbers):
return sum(numbers) / len(numbers)
print(mean_2(a_list))
size = 5
# 08
for row in range(1, size + 1):
for columns in range(row):
print("*", end="")
print()
for row in range(1, size + 1)[::-1]:
for columns in range(row):
print("*", end="")
print()
# 09
def check_odd(number):
return 'Odd' if number % 2 else 'Even'
print(check_odd(2))
# 10
mixed_list = [42, 3.14, "hello", 7, 2.718, "world", 10]
def check_val_list(items):
new_list = []
new_list_str = []
new_list_int = []
for item in items:
if isinstance(item, float):
new_list.append(item)
if isinstance(item, str):
new_list_str.append(item)
else:
new_list_int.append(item)
return new_list, new_list_str, new_list_int
print(check_val_list(mixed_list))
# 11
mixed_list_2 = [42, 3.14, "hello", True, [1, 2, 3], {'key': 'value'}, None, (4, 5), 'world', False]
def create_list_last_3_index(items):
new_list = []
for item in items[:-4:-1]:
new_list.append(item)
return new_list
print(f'The new list made up of last three indexes of mixed list :\n{create_list_last_3_index(mixed_list_2)}')
def array_madness(a, b):
return sum([num_a ** 2 for num_a in a]) > sum([num_b ** 3 for num_b in b])
print(array_madness([61], [5, 18, 26, 17, 19, 14, 28, 13, 27]))
def sum_array(arr):
# return sum(list(set(sorted(arr)))[1:-1])
return sum(sorted(arr)[1:-1])
print(sum_array([6, 0, 1, 10, 10]))
def sum_array_1(arr):
return sum(sorted(arr)[1:-1]) if len(arr) > 2 else 0
print(sum_array_1([3, 5]))
print(sum_array_1([5]))
print(sum_array_1([]))
def rps(p1, p2):
beats = {'rock': 'scissors', 'scissors': 'paper', 'paper': 'rock'}
if beats[p1] == p2:
return "Player 1 won!"
if beats[p2] == p1:
return "Player 2 won!"
return "Draw!"
def rps_1(p1, p2):
hand = {'rock': 0, 'paper': 1, 'scissors': 2}
results = ['Draw!', 'Player 1 won!', 'Player 2 won!']
return results[hand[p1] - hand[p2]]
def count_sheeps(sheep):
# TODO May the force be with you
return str(sheep).count('True')
def eliminate_sth_in_list(any_list):
return [item for item in any_list if item is not bool].count(5)
print(eliminate_sth_in_list([True, True, True, False,
True, True, 5, True,
True, 2, True, False,
True, False, False, True,
True, 5, True, True,
False, False, True, True]))
def summation(num):
return sum(item for item in range(1, num + 1))
def number(bus_stops):
sum_index_0 = 0
sum_index_1 = 0
for element in bus_stops:
sum_index_0 += element[0]
sum_index_1 += element[1]
return sum_index_0 - sum_index_1
def number_1(bus_stops):
sum_index_0 = sum(element[0] for element in bus_stops)
sum_index_1 = sum(element[1] for element in bus_stops)
return sum_index_0 - sum_index_1
def number_2(bus_stops):
return sum([stop[0] - stop[1] for stop in bus_stops])
def number_3(bus_stops):
sum = 0
for i in bus_stops:
sum += i[0] - i[1]
return sum
from functools import reduce
def grow(arr):
return reduce(lambda x, y: x * y, arr)
def grow_1(arr):
product = 1
for i in arr:
product *= i
return product
def powers_of_two(n):
return [2 ** num for num in range(0, n + 1)]
def how_much_i_love_you(nb_petals):
phrases = ["I love you", "a little", "a lot", "passionately", "madly", "not at all"]
index = (nb_petals - 1) % len(phrases)
return phrases[index]
def find_multiples(integer, limit):
return [num for num in range(integer, limit + 1) if not num % integer]
def count_squares(cuts):
return (cuts + 1) ** 3 - (cuts - 1) ** 3
def count_squares_1(x):
return 6 * x ** 2 + 2
def sort_array(source_array):
return sorted(item for item in source_array if item % 2)
print(sort_array([5, 8, 6, 3, 4]))
def sort_array_2(source_array):
odd_numbers = sorted(item for item in source_array if item % 2)
return [even if even % 2 == 0 else odd_numbers.pop(0) for even in source_array]
def well(x):
return 'Fail!' if x.count('good') == 0 else 'Publish!' if x.count('good') <= 2 else 'I smell a series!'
def well_2(x):
if x.count('good') == 0:
return 'Fail!'
elif x.count('good') <= 2:
return 'Publish!'
else:
return 'I smell a series!'
def cube_checker(volume, side):
return abs(volume ** (1 / 3) - side) < 1e-10 if volume > 0 and side > 0 else False
def simple_multiplication(number):
return 8 * number if not number % 2 else 9 * number
def rot13(message):
result = ''
for char in message:
if char.isalpha():
shift = 13 if char.islower() else -13
result += chr(
(ord(char) - ord('a' if char.islower() else 'A') + shift) % 26 + ord('a' if char.islower() else 'A'))
else:
result += char
return result
def duplicate_encode(word):
word = word.lower()
return ''.join([')' if word.count(char) > 1 else '(' for char in word])
def collinearity(x1, y1, x2, y2):
return x1 * y2 == x2 * y1
def validate_pin(pin):
return (len(pin) == 4 or len(pin) == 6) and pin.isdigit()
def validate_pin_2(pin):
return len(pin) in [4, 6] and pin.isdigit()
def set_alarm(employed, vacation):
return employed and not vacation
def string_to_array(s):
return s.split() or ['']
def string_to_array_2(string):
return string.split(" ")
def switch_it_up(number):
numbers_dict = {
0: "Zero",
1: "One",
2: "Two",
3: "Three",
4: "Four",
5: "Five",
6: "Six",
7: "Seven",
8: "Eight",
9: "Nine"
}
if number in numbers_dict:
return numbers_dict[number]
def switch_it_up_1(n):
return ['Zero', 'One', 'Two', 'Three', 'Four', 'Five', 'Six', 'Seven', 'Eight', 'Nine'][n]
def switch_it_up_3(number):
dict = {
1: "One",
2: "Two",
3: "Three",
4: "Four",
5: "Five",
6: "Six",
7: "Seven",
8: "Eight",
9: "Nine",
0: "Zero"}
return dict.get(number)
def domain_name(url):
url = url.split("//")[-1]
if url.startswith("www."):
url = url[4:]
url = url.split("/")[0]
if "." in url:
parts = url.split(".")
if len(parts) > 2:
if parts[-1] in ["com", "net", "org", "jp", "za", "uk"]:
url = parts[-3]
else:
url = parts[-2]
else:
url = parts[0]
return url
def domain_name_1(url):
return url.split("//")[-1].split("www.")[-1].split(".")[0]
def tribonacci_1(signature, n):
if n == 0:
return []
elif n <= len(signature):
return signature[:n]
else:
result = signature[:]
for i in range(n - len(signature)):
next_term = sum(result[-3:])
result.append(next_term)
return result
def tribonacci(signature, n):
res = signature[:n]
for i in range(n - 3): res.append(sum(res[-3:]))
return res
def printer_error(s):
error_count = sum(1 for char in s if char > 'm')
return f"{error_count}/{len(s)}"
def invert(lst):
return [-x for x in lst]
def define_suit(card):
if 'C' in card:
return 'clubs'
if 'D' in card:
return 'diamonds'
if 'H' in card:
return 'hearts'
if 'S' in card:
return 'spades'
def define_suit_1(card):
d = {'C': 'clubs', 'S': 'spades', 'D': 'diamonds', 'H': 'hearts'}
return d[card[-1]]
def define_suit_2(card):
return {'C': 'clubs', 'S': 'spades', 'D': 'diamonds', 'H': 'hearts'}[card[-1]]
def ensure_question(s):
return s + '?' if not s.endswith('?') else s
def ensure_question_2(s):
return s if s.endswith('?') else s + '?'
def ice_brick_volume(radius, bottle_length, rim_length):
return (((2 * radius) ** 2) * (bottle_length - rim_length)) / 2
def longest(a1, a2):
return ''.join(sorted(set(a1 + a2)))
def count_smileys(arr):
return sum([1 for sign in arr if
len(sign) == 2 and sign[0] in (':', ';') and sign[1] in (')', 'D') or len(sign) == 3 and sign[0] in (
':', ';') and sign[1] in ('-', '~') and sign[2] in (')', 'D')])
def duck_duck_goose(players, goose):
return players[(goose - 1) % len(players)].name
def same_case(a, b):
if not a.isalpha() or not b.isalpha():
return -1
elif a.islower() == b.islower() or a.isupper() == b.isupper():
return 1
else:
return 0
def same_case_1(a, b):
return a.isupper() == b.isupper() if a.isalpha() and b.isalpha() else -1
def min_max(lst):
return [min(lst), max(lst)]
def sum_dig_pow(a, b):
def is_eureka(num):
digits = [int(digit) for digit in str(num)]
return num == sum(digit ** (index + 1) for index, digit in enumerate(digits))
return sorted(num for num in range(a, b + 1) if is_eureka(num))
def dig_pow(n):
return sum(int(x) ** y for y, x in enumerate(str(n), 1))
def sum_dig_pow_2(a, b):
return [x for x in range(a, b + 1) if x == dig_pow(x)]
def sum_dig_pow_3(a, b):
return [x for x in range(a, b + 1) if sum(int(d) ** i for i, d in enumerate(str(x), 1)) == x]
def flick_switch(lst):
switch = True
return [switch := not switch if word == 'flick' else switch for word in lst]
def multiply(n):
return n * 5 ** len(str(abs(n)))
def take(arr, n):
return arr[:n]
def usdcny(usd):
return f"{round(usd * 6.75, 2)} Chinese Yuan"
def usdcny(usd):
return f"{round(usd * 6.75, 2):.2f} Chinese Yuan"
def hello(name=""):
return "Hello, World!" if not name else f'Hello, {name.capitalize()}!'
def greet(language):
dictionary = {
"english": "Welcome",
"czech": "Vitejte",
"danish": "Velkomst",
"dutch": "Welkom",
"estonian": "Tere tulemast",
"finnish": "Tervetuloa",
"flemish": "Welgekomen",
"french": "Bienvenue",
"german": "Willkommen",
"irish": "Failte",
"italian": "Benvenuto",
"latvian": "Gaidits",
"lithuanian": "Laukiamas",
"polish": "Witamy",
"spanish": "Bienvenido",
"swedish": "Valkommen",
"welsh": "Croeso"
}
return dictionary.get(language, 'Welcome')
def get_key(dictionary, value):
for key, val in dictionary.items():
if val == value:
return key
return None
def get_key_1(dictionary, value):
return next((key for key, val in dictionary.items() if val == value), None)
def include(arr, item):
return item in arr
def each_cons(lst, n):
return [lst[i:i + n] for i in range(len(lst) - n + 1)]
def merge_arrays(arr1, arr2):
return list(sorted(set(arr1 + arr2)))
def mouth_size(animal):
return 'small' if animal.lower() == 'alligator' else 'wide'
def is_digit(n):
return len(n) == 1 and n.isdigit() and int(n) in range(0, 10)
def to_freud(sentence):