
What can I fix about this code to program it to display ONLY duplicates instead of with non-duplicates?
Prompt for reference:
Write a console app that inserts 30 random letters into a List<char>. Perform the following queries on the List and display your results: [Hint: Strings can be indexed like arrays to access a character at a specific index.]
Use LINQ to sort the List in ascending order.
Use LINQ to sort the List in descending order.
Display list with ONLY duplicates
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace List
{
class Program
{
static void Main(string[] args)
{
//Create a Random object
Random rand = new Random();
//Create a List of type to store 30 random values
List<char> list = new List<char>(30);
//Generate a random number and insert a character into the list
for (int i = 0; i < 30; i++)
{
int r = rand.Next(30) + 1;
//insert letters that starts from 'a'
list.Add((char)(r + 'a'));
}
Console.WriteLine("Before Sorting");
//Print before sorting
foreach (var item in list)
Console.WriteLine("{0}", item);
//Call OrderBy for each element in ascending order
List<char> sortedList = list.OrderBy(n => n).ToList();
Console.WriteLine("After ascending order sorting");
//Print ascnding sorted list
foreach (var item in sortedList )
Console.WriteLine("{0}", item);
//Call orderByDescending for each element
List<char> decendingList = list.OrderByDescending(n => n).ToList();
Console.WriteLine("After Descending order sorting");
//Print decending sorted list
foreach (var item in decendingList )
Console.WriteLine("{0}", item);
List<char> uniqueSortedList = sortedList.Distinct().ToList();
}
}
}

Step by stepSolved in 4 steps with 3 images

- In Kotlin, Create a list that uses your area function as an initializer and contains the areas of circles with each integer from 1 to 25 as radius.arrow_forwardModify the code below the #S11icq Q5 comment as you enter code for this task. Modify the code that creates the variable sf to assign the value in index position 2 of the list fish Modify the loop to repeat exactly four times . Click on the Run Current Script function (use menu at top of Thonny). Match the following: 1. 18500967 2. 237233811 updated value of sm 3. 35 updated value of sg_h 4. 44 updated value of sg_c 5. 2 6. 3 6arrow_forwardLists and strings: Perform the following using the list and string defined below: Mylist = [“orange”,”banana”,”apple”,”grape”] Mystring = “314-800-2346” What does Mylist[2] equal? What does Mystring[2] equal? What does the len(Mylist) equal? What does len(Mystring) equal? Write a for loop that will display the strings in Mylist from last to first. Write a line of code that appends “pear” to Mylistarrow_forward
- 10 - question You should use a Set instead of a List if you want to avoid duplicates (True/False)? a. True b. Falsearrow_forwardA list will store data in Key: Value pairs. a. True b. Falsearrow_forwardAssume that the variable data refers to the list [5, 3, 7]. Write the expressions that perform the following tasks: a. Replace the value at position o in data with that value's negation. b. Add the value 10 to the end of data. c. Insert the value 22 at position 2 in data. d. Remove the value at position 1 in data. e. Add the values in the list newData to the end of data. f. Locate the index of the value 7 in data, safely. g. Sort the values in data.arrow_forward
- {7,14,26,43,46,50,81} trace the binary search code and fill out the table for 3 different cases: Search for the value that is in the table. Search for the value that is greater than any value in the list. Search for the value that is smaller than any value in the list. low high Low<high mid callarrow_forwardSA1: What is the maximum number of values linear search must check to find a value in a list with 2 billion values? SA2: What is the maximum number of values binary search must check to find a value in a list with 2 billion values?arrow_forward4 ete t of With the following lists: list1 = [x + y for x in ['a', 'b', 'c'] for y in ['1', '2', '3']] list2 = [[x + y for x in ['a', 'b', 'c']] for y in ['1', '2', '3']] which option is true? Select one: A. len(list1)> len(list2) B. 'a1' is an element (or subelement) for list1 whereas '1a' is for list2 C. list1 and list2 will error because numbers and letters cannot be added. D. Both A and B are true.arrow_forward
- PYTHON Complete the function below, which takes two arguments: data: a list of tweets search_words: a list of search phrases The function should, for each tweet in data, check whether that tweet uses any of the words in the list search_words. If it does, we keep the tweet. If it does not, we ignore the tweet. data = ['ZOOM earnings for Q1 are up 5%', 'Subscriptions at ZOOM have risen to all-time highs, boosting sales', "Got a new Mazda, ZOOM ZOOM Y'ALL!", 'I hate getting up at 8am FOR A STUPID ZOOM MEETING', 'ZOOM execs hint at a decline in earnings following a capital expansion program'] Hint: Consider the example_function below. It takes a list of numbers in numbers and keeps only those that appear in search_numbers. def example_function(numbers, search_numbers): keep = [] for number in numbers: if number in search_numbers(): keep.append(number) return keep def search_words(data, search_words):arrow_forwardIn the function below, return the last element (the one at the last index) of the list provided as the parameter called list1. Assume that the argument is a list.arrow_forwardmyStrList = ["this", "is", "my", "str", "list", 0] for s in myStrList: print(s)arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education





