Featured post

How to Use Special Keys in UNIX

UNIX operating system has some special keys. These you can use to interrupt the program processing or to resume it. The file management and keys totally different in UNIX kinds of operating systems. 



An example of a UNIX special key and its use.
Special Keys in UNIX much useful to take action  when something happens.

1. Why You Need Program Interruption in UNIX.

A scenario where you made some mistake in the input command and you need to stop the further process. Then you can use the CTRL+C command. It is equal to the DELETE command.

2. List of UNIX Special Keys.

RETURN key 
The RETURN key signifies the end of a line of input. On any terminal, RETURN has a key of its own, or return may be typed by holding down the control key and typing a 'm'.

CTRL-m Key
Hint: Ctrl-m command is equal to RETURN key in Unix systems


DELETE Key
The DELETE key stops a program/command immediately, without waiting for it to finish. DELETE can be achieved equivalently with ctrl-c.
Hint: Ctrl-c Command you can use …

Python Remove Duplicates from List Top Ideas

In real-time, it is common you can find duplicates in the list. But when you use the same data for analysis ( Pyhton list duplicate values), the data may not give the correct results. So I am sharing top ideas to remove duplicates from Python list.


Python Remove Duplicates from List Top Ideas

Idea: #1 How to Remove Duplicates From List


# Given a list with duplicates

list_with_duplicates = [1,2,3,12,1,2,3,4,5,6,1,2,3,7,8,9]
The first approach might be a simple brute force approach:

list_without_duplicates = []
for pd in list_with_duplicates:
  if pd not in list_without_duplicates:
   list_without_duplicates.append(pd)

print(list_without_duplicates)
[1, 2, 3, 12, 4, 5, 6, 7, 8, 9]

As you can see, this method works. It has some performance issues for large lists since you are essentially creating a full copy of the list. Surely we can do better than that? We can, in fact, do somewhat better than that. Let's try a different method, this time using a dictionary to hold our intermediary values:

Idea: #2 How to Remove Duplicates From List


# Convert the list to a dictionary
dictionary_without_duplicates =
dict(zip(list_with_duplicates, list_with_duplicates))

print(dictionary_without_duplicates)
{1: 1, 2: 2, 3: 3, 12: 12, 4: 4, 5: 5, 6: 6, 7: 7, 8: 8, 9: 9}

Once again, this works and has the advantage of taking less space than duplicating the entire list. Of course, we still need to convert it back to a list when we are done, which might be somewhat painful since we must extract the keys and add them to a list.

Comments

Popular posts from this blog

How to Use Special Keys in UNIX

How to Categorise Python Top Uses

10 Top Unix Disk Space Quiz Questions

Hyperledger Fabric: 20 Real Interview Questions

5 Super SEO Blogger Tools

5 Top Features People Need Today in Modern Devices