-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexercises.py
110 lines (97 loc) · 3.22 KB
/
exercises.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
# # CodeWar Exercise
# codewar = You only need one - Beginner
# Description:
# You will be given an array a and a value x. All you need to do is check whether the provided array contains the value.
#
# Array can contain numbers or strings. X can be either.
#
# Return true if the array contains the value, false if not.
# My Solution
# def check(seq, elem):
# print(seq, elem)
# checked = False
# for x in seq:
# if x == elem and not checked:
# checked = True
# break
# print(checked)
#
# check ((66, "codewars", 11, "alex loves pushups"), "alex loves pushups")
# codewar = Meeting
# Description:
# John has invited some friends. His list is:
#
# s = "Fred:Corwill;Wilfred:Corwill;Barney:Tornbull;Betty:Tornbull;Bjon:Tornbull;Raphael:Corwill;Alfred:Corwill";
# Could you make a program that
#
# makes this string uppercase
# gives it sorted in alphabetical order by last name.
# When the last names are the same, sort them by first name. Last name and first name of a guest come in the result between parentheses separated by a comma.
#
# So the result of function meeting(s) will be:
#
# "(CORWILL, ALFRED)(CORWILL, FRED)(CORWILL, RAPHAEL)(CORWILL, WILFRED)(TORNBULL, BARNEY)(TORNBULL, BETTY)(TORNBULL, BJON)"
# It can happen that in two distinct families with the same family name two people have the same first name too.
# My Solution
# s = "Fred:Corwill;Wilfred:Corwill;Barney:Tornbull;Betty:Tornbull;Bjon:Tornbull;Raphael:Corwill;Alfred:Corwill"
# #def meeting(s):
# first_name = []
# family_name =[]
# capital_name=[]
# person =''
# result= ''
# for letter in s:
# if letter != ';' and letter != ':':
# person += letter
# elif letter == ':':
# first_name.append(person)
# person = ''
# elif letter == ';' :
# family_name.append(person)
# person = ''
# family_name.append(person)
# for i in range (len(first_name)):
# capital_name.append(family_name[i].upper()+', '+ first_name[i].upper())
# capital_ordered =sorted(capital_name)
# for people in capital_ordered:
# result+='('
# result+= people
# result+=')'
# result += ''
# print(result)
# # Best Solution 1
# s = "Fred:Corwill;Wilfred:Corwill;Barney:Tornbull;Betty:Tornbull;Bjon:Tornbull;Raphael:Corwill;Alfred:Corwill"
# s = s.upper()
# print(s)
# s = s.split(';') # If you split ':' s became a tuple --> I try but I was not able to do it
# print(s)
# array = []
# string = ""
# for i in s:
# i = i.split(':')
# string = '('+i[1]+', '+i[0]+')'
# array.append(string)
# array.sort()
# output = ""
# for j in array:
# output += j
# print(output)
#
# # # Best Solution 2 --> same logic Solution above
# # def meeting(s):
# # names = s.upper().split(';')
# # return ''.join(sorted('({1}, {0})'.format(*(n.split(':'))) for n in names))
#
# # # Best Solution 3 --> Not able to understand
# # meeting=lambda s:''.join(sorted('(%s, %s)'%tuple(e.split(':')[::-1])for e in s.upper().split(';')))
gridline = []
for i in range(7):
gridline.append(0)
grids = []
for i in range(6):
grids.append(list(gridline))
print('Current Grid:')
print(*grids, sep='\n')
for line in grids[5]:
print(line)
# codewar = Greed is Good