Skip to content

Elso hazi #22

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 24 additions & 4 deletions basic/list1.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,12 @@
# Note: python does not have a ++ operator, but += works.
def match_ends(words):
# +++your code here+++
return

szamlalo=0
for elem in words:
if len(elem)>=2 and elem[0]==elem[-1]:
szamlalo+=1

return szamlalo

# B. front_x
# Given a list of strings, return a list with the strings
Expand All @@ -34,7 +38,15 @@ def match_ends(words):
# before combining them.
def front_x(words):
# +++your code here+++
return
x_lista = []
nem_x_lista = []
for elem in words:
if elem[0] == 'x':
x_lista.append(elem)
else:
nem_x_lista.append(elem)

return sorted(x_lista) + sorted(nem_x_lista)


# C. sort_last
Expand All @@ -45,7 +57,15 @@ def front_x(words):
# Hint: use a custom key= function to extract the last element form each tuple.
def sort_last(tuples):
# +++your code here+++
return
sorted_tuples=[0 for i in range(len(tuples))]
szamok=[]
for elem in tuples:
szamok.append(elem[-1])
sorted_szamok=sorted(szamok)
for elem in tuples:
sorted_tuples[sorted_szamok.index(elem[-1])]=elem

return sorted_tuples


# Simple provided test() function used in main() to print
Expand Down
10 changes: 8 additions & 2 deletions basic/list2.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@
# modify the passed in list.
def remove_adjacent(nums):
# +++your code here+++
return
l = []
for i in range(len(nums)-1):
if nums[i] != nums[i+1]:
l.append(nums[i])
if i == len(nums)-2:
l.append(nums[i+1])
return l


# E. Given two lists sorted in increasing order, create and return a merged
Expand All @@ -23,7 +29,7 @@ def remove_adjacent(nums):
# pass of both lists.
def linear_merge(list1, list2):
# +++your code here+++
return
return sorted(list1+list2)


Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Helyes a megoldas, de sajnos nem fut eleg gyorsan (should run in linear time)

# Note: the solution above is kind of cute, but unforunately list.pop(0)
Expand Down
13 changes: 9 additions & 4 deletions basic/string1.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@
# and donuts(23) returns 'Number of donuts: many'
def donuts(count):
# +++your code here+++
return
if count < 10:
return 'Number of donuts: ' + str(count)
else:
return 'Number of donuts: many'


# B. both_ends
Expand All @@ -35,7 +38,7 @@ def donuts(count):
# is less than 2, return instead the empty string.
def both_ends(s):
# +++your code here+++
return
return s[:2]+s[-2:]


# C. fix_start
Expand All @@ -49,7 +52,9 @@ def both_ends(s):
# where all instances of stra have been replaced by strb.
def fix_start(s):
# +++your code here+++
return
sztring=s[1:]
a=sztring.replace(s[0],'*')
return s[0]+a


# D. MixUp
Expand All @@ -61,7 +66,7 @@ def fix_start(s):
# Assume a and b are length 2 or more.
def mix_up(a, b):
# +++your code here+++
return
return b[:2]+a[2:]+' '+a[:2]+b[2:]


# Provided simple test() function used in main() to print
Expand Down
21 changes: 18 additions & 3 deletions basic/string2.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@
# Return the resulting string.
def verbing(s):
# +++your code here+++
return
if s[-3:]=='ing:
return s[:-3]+'ly'
elif len(s)<3:
return s
else:
return s+'ing'


# E. not_bad
Expand All @@ -30,7 +35,10 @@ def verbing(s):
# This dinner is good!
def not_bad(s):
# +++your code here+++
return
not_index=s.find('not')
bad_index=s.find('bad')

return s[:not_index]+'good'+s[bad_index+3:]


# F. front_back
Expand All @@ -42,7 +50,14 @@ def not_bad(s):
# a-front + b-front + a-back + b-back
def front_back(a, b):
# +++your code here+++
return
def splits(x):
if len(x)%2==0:
half = len(x)/2
return [x[:int(half)],x[int(half):]]
else:
half = len(x)/2
return [x[:int(half)+1],x[int(half)+1:]]
return splits(a)[0]+splits(b)[0]+splits(a)[1]+splits(b)[1]


# Simple provided test() function used in main() to print
Expand Down