How to make the names stored in a list unique?
I created a variable that will prompt users to input their names 20x, the all those names will be appended into an empty list that I created, but I need a function that will constant check each name that was entered and compare it to other names in the list in order to ensure that it is unique, if similarity is found, the function should automatically add a unique number to that name to make it unique. The function should also enable users to enter not more than 20 characters and not less than 3 characters for their names. Id really appreciate it if someone can help me with this problem, thanks in advance. Also I would like it to be done with python programming language.
Here is an example of how i have tried to make the validation
do you know?
how many words do you know
See also questions close to this topic
-
How can I use functional update with event.currentTarget.value in React?
First, please check my code.
const [name, setName] = useState('nick'); const handleChangeName = (e) => { setName(prevState => e.currentTarget.value) } return ( <input value={name} onChange={handleChangeName} /> )
I'm trying to do functional update not
setName(e.currentTarget.value)
However, with this code,
const handleChangeName = (e) => { setName(prevState => e.currentTarget.value) }
I am not getting the right value for some reason. If you know what is the problem or the answer, please let me know! Thank you.
-
How to get pass an array through a function with a user input?
I want to ask the user for the size of a 2D array arr[][], but also pass it through the function initializeArray. However, if I pass it through the function, I would have to have a size declarator for col, which doesn't allow the user to enter their own value for the size
#include<iostream> using namespace std; void initializeArray(arr[][10], int N); int main() { int N; cout << "enter an array size: "; cin >> N; int arr[N][N]; initializeArray(arr, N); // I get an error here for(int i = 0; i < N; i++) { for(int j = 0; j < N; j++) cout << arr[i][j] << " "; cout << endl; } } void initializeArray(int arr[][10], int N) { for(int i = 0; i < N; i++) for(int j = 0; j < N; j++) arr[i][j] = 0; }
The only solution I found was the make arr[][] a global array, but in that case, I would have to still declare the size parameters, and I want the user to enter whatever they want. Is there another way to fix this?
-
Two-dimensional array C++
Problem: Write a program of a two dimensional integer array of exactly four rows and four columns, and find the sum of the integers each row of the array as well as determine the smallest inputted element/data in the array. The user will input the elements. Display the elements in tabular form. Make the program user friendly. Use a Class and a member function for the process involve.
-
Matching number with regex
Need a single combined regex to match the following logic: The number should be 8 digits long, the 8th digit should be the remainder of (the first 7 digits / 7).
for example: 86008786
remainder = (the first 7 digit)/ 7 = 8600878 / 7 = 6
so the 8 digit 86008786 is valid number.
is it doable with regex?
-
Validation Control are not working on live server [Google Cloud] with VS 2015 (Asp.Net with C#)
On my local machine everything is working fine...but on live server validation control are not working. [I am using Google Cloud (Windows Server 2019)].
I am using VS 2015 (Asp.Net Web Form with c#))
my code is here...
<asp:TextBox ID="txtFirstName" runat="server" placeholder="Your First Name" MaxLength="25" ></asp:TextBox> <asp:RequiredFieldValidator ID="rfvFirstName" runat="server" ControlToValidate="txtFirstName" Display="Dynamic" ErrorMessage="First Name is required." SetFocusOnError="True" ValidationGroup="v" ForeColor="Red"></asp:RequiredFieldValidator> <asp:Button ID="btnSubmit" runat="server" Text="Submit" ValidationGroup="v" />
I read some articles related to this. According to them I added below code in my web.config file but still issue are same...
<add key="ValidationSettings:UnobtrusiveValidationMode" value="None" /> <!--Using 4.5 Version only-->
-
Struts2 field validator - Validate multiple fields together
As part of my project I have the credit card month and year as two different fields,
<field name="expiry-month"> <field-validator> ... </field-validator> </field> <field name="expiry-year"> <field-validator> ... </field-validator> </field>
Now, I want to validate the values of these two fields as together so that the credit card expiry month and year are not in past.
How can I do that within XML?
Thank you.
-
How can I read from a file in c until a character is reached?
sara,fahmi,sarafah@yahoo.fr,secret5648,UIR,undergrad,Rabat,UK,what is my favourite color?,blue,400246212432285,418,03/21/2023
I want to store this line in different arrays. For example store sara in first name, fahmi in last name...
-
character case on a Loop
can't seem to figure this out. Need to display the same characters as the input (top highlighted) instead of it being capitalized. It was only capitalize for comparison. See attached photo. Thanks.
-
How do I reverse characters within nested brackets in R?
I am trying to solve the following problem:
"Write a function that reverses characters in (possibly nested) parentheses in the input string.
Input strings will always be well-formed with matching ()s.
Example
For
inputString = "(bar)",
the output should be
solution(inputString) = "rab";
For
inputString = "foo(bar)baz",
the output should be
solution(inputString) = "foorabbaz";
For
inputString = "foo(bar)baz(blim)",
the output should be
solution(inputString) = "foorabbazmilb";
For
inputString = "foo(bar(baz))blim",
the output should be
solution(inputString) = "foobazrabblim".
Because
"foo(bar(baz))blim"
becomes
"foo(barzab)blim"
and then
"foobazrabblim".
Now I have managed to solve the problem for the simple case when there is just one pair of brackets – i.e. unnested and without a second pair. My code:
solution <- function(inputString) { a <- unlist(strsplit(x=inputString,split="")) bracket.indices <- grep(pattern="\\(|\\)",x=a) a[(bracket.indices[1] + 1): (bracket.indices[2] - 1)] <- rev(a[(bracket.indices[1] + 1): (bracket.indices[2] - 1)]) return(paste(a <- a[-bracket.indices])) }
So I first split the string so that I can access individual elements by indices. Next, I use grep to identify the indices of the brackets, and then I use those indices to access the characters within the brackets and reverse them, using rev(). Finally, I get rid of the brackets and then use paste() to collapse the split string back down into a normal string. Obviously, if there is a second pair of brackets – e.g. we have
inputString = "foo(bar)baz(blim)"
my code won't work because I've assumed bracket.indices has just two elements and accessed them accordingly. What's more, my code obviously won't work for nested brackets because the contents of nested brackets need to be reversed altogether with the contents of outer brackets.
Probably in solving the problem for this simple case I have just distorted the proper solution, but since the larger problem is a bit baffling to me, going about it in the simple case is the best place I could think to start. Any help? (Base R would be preferred)
-
Laravel: Feature test json validations unique rule issue
I recently started implementing the unit testing in
Laravel 9.x
framework. So far, I was able to write some basic rules without any complications. However, in my application I am validating the forms usingajax
andFrom Request
for validation rules.CategoryRequest.php
class CategoryRequest extends FormRequest { /** * Get the validation rules that apply to the request. * * @return array */ public function rules() { return [ // ... 'title' => [ 'required', 'max:255', function($attributes, $value, $fails) { $Category = Category::where([ 'user_id' => request()->user_id, 'title' => request()->title, ])->first(); if($Category) { $fails('`Category` is already taken'); } } ], // ... ]; } }
CategoryTest.php
class CategoryTest extends TestCase { use RefreshDatabase; // ... public function test_new_category_with_unique_validation() { $user = $this->__user(); $arrayPost = [ 'user_id' => $user->id, 'uuid' => Str::uuid(), 'title' => 'title', 'status' => STATUS['active'], ]; Category::factory()->create($arrayPost); $response = $this ->actingAs($user) ->post('/console/categories', $arrayPost); $response->assertJsonValidationErrorFor('title'); $response->assertJsonValidationErrorFor('status'); $response->assertJsonValidationErrorFor('uuid'); $response->assertJsonValidationErrorFor('user_id'); } private function __user(): object { return User::factory()->create(); } }
I am getting the following error...
What am I doing wrong?
-
How to select distinct value
I need to select all supervisor records. Our HR employee table set up like below
Firstname Lastname Email Supervisor Frank Johns fjohns Taylor, Don Pat Hope phope Taylor, Don Jen Dow jdow Taylor, Don Taylor Don tdon Olson, Mike Kim Ronda kronda Olson, Mike Rob Smith rsmith Olson, Mike Mike Olson molson null The final result should be like this
Firstname Lastname Email Supervisor Taylor Don tdon Olson, Mike Mike Olson molson null If I use Distinct on supervisor then it gives me a list of supervisor but not their info. Please help
-
SQL Match records in any order
Given a table like
OBJECTID,UID,FID1,FID2 1,Record1,00000494e1f3,00000494e1f3 2,Record2,00000494e1ed,00000494e1ed 3,Record3,eff9df49d9ec,6d1f58545043 4,Record4,6d1f58545043,eff9df49d9ec 5,Record5,37fce22b2bb5,7fce22b2bb5 6,Record6,00000494e1ef,00000494e1ef
We can see that in records 3 and 4 the FID1 and FID2 values are the same but just in a different order.
I can simply concatenate the FID1 and FID2 values and then run unique on that column but this won't give us case where FID1/2 are the same but just in a different order.
See https://www.db-fiddle.com/f/gp3vYGhB9cgYUukcEwM3K3/1
How can I find all records where the FID1 and FID2 values are the same but just in a different order?
-
treeview grandfather,parent and son names
I have tree view which has grandfather node and inside of this grandfather there is parent and inside this parent there is son node. How I can get the names of this grandfather , parent and son nodes. I already did the code to work when the user double clicks on the son node, but still I am unable to get the names for the grandfather, parent and child nodes. here is my code:
Private Sub TreeView1_NodeMouseDoubleClick(sender As Object, e As TreeNodeMouseClickEventArgs) Handles TreeView1.NodeMouseDoubleClick Dim ClickPoint As Point = New Point(e.X, e.Y) Dim ClickedChildNode As TreeNode = TreeView1.GetNodeAt(ClickPoint) If ClickNode Is Nothing Then Exit Sub End If Dim strGrandFatherName As String Dim strParentName As String Dim strSonName As String strGrandFatherName = ? strParentName = ? strSonName = ?
-
How do I prevent submitting duplicate names in a form
I am trying to figure out how to not allow duplicate names to be entered by the user.
function addKitten(event) { event.preventDefault() let form = event.target let kitten = { id: generateId(), name: form.name.value, mood: "Tolerant", affection: 5, } console.log(kitten); kittens.push(kitten) saveKittens() form.reset() drawKittens() }