Naman
BAN USERWe can create a new blank list for unique numbers of the list. While iterating the input list, check if the number found in the uninque_list then it must be duplicate, else unique and should be added to unique_list.
def find_duplicate(list_num):
unque_list,duplicate_list = [],[]
for number in list_num:
if number in unque_list:
print "duplicate number found - %s" % number
duplicate_list.append(number)
else:
unque_list.append(number)
return (unque_list,list(set(duplicate_list)))
With Python:
def reverse_string(input_str):
return input_str[::-1]
def reverse_string_space_check(input_str):
out_str,low_index = "",0
for id,ch in enumerate(input_str):
if ch == " ":
if low_index == id:
# This check will reduce the number of calls of reverse_string function
# code will work fine even without the if check and just keeping whatever
# in else part
out_str = out_str + " "
else:
out_str = out_str + reverse_string(input_str[low_index:id]) + " "
low_index = id+1
else:
out_str = out_str + reverse_string(input_str[low_index:])+" "
return out_str
We can create a list ehich contains unique elements from input list. Then iterate over the unique list and check the count of number, if not 3 then add to return list
- Naman July 25, 2015