Telegram Group & Telegram Channel
Sorts one list based on another list containing the desired indexes.

Use zip() and sorted() to combine and sort the two lists, based on the values of indexes.

Use a list comprehension to get the first element of each pair from the result.

Use the reverse parameter in sorted() to sort the dictionary in reverse order, based on the third argument.

CODE:

def sort_by_indexes(lst, indexes, reverse=False):
return [val for (_, val) in sorted(zip(indexes, lst), key=lambda x: \
x[0], reverse=reverse)]

Example:

a = ['eggs', 'bread', 'oranges', 'jam', 'apples', 'milk']

b = [3, 2, 6, 4, 1, 5]

sort_by_indexes(a, b)

Output:
['apples', 'bread', 'eggs', 'jam', 'milk', 'oranges']

sort_by_indexes(a, b, True)

Output:
['oranges', 'milk', 'jam', 'eggs', 'bread', 'apples']

Share and Support
@Python_Codes



tg-me.com/python_codes/179
Create:
Last Update:

Sorts one list based on another list containing the desired indexes.

Use zip() and sorted() to combine and sort the two lists, based on the values of indexes.

Use a list comprehension to get the first element of each pair from the result.

Use the reverse parameter in sorted() to sort the dictionary in reverse order, based on the third argument.

CODE:

def sort_by_indexes(lst, indexes, reverse=False):
return [val for (_, val) in sorted(zip(indexes, lst), key=lambda x: \
x[0], reverse=reverse)]

Example:

a = ['eggs', 'bread', 'oranges', 'jam', 'apples', 'milk']

b = [3, 2, 6, 4, 1, 5]

sort_by_indexes(a, b)

Output:
['apples', 'bread', 'eggs', 'jam', 'milk', 'oranges']

sort_by_indexes(a, b, True)

Output:
['oranges', 'milk', 'jam', 'eggs', 'bread', 'apples']

Share and Support
@Python_Codes

BY Python Codes


Warning: Undefined variable $i in /var/www/tg-me/post.php on line 283

Share with your friend now:
tg-me.com/python_codes/179

View MORE
Open in Telegram


Python Codes Telegram | DID YOU KNOW?

Date: |

How to Use Bitcoin?

n the U.S. people generally use Bitcoin as an alternative investment, helping diversify a portfolio apart from stocks and bonds. You can also use Bitcoin to make purchases, but the number of vendors that accept the cryptocurrency is still limited. Big companies that accept Bitcoin include Overstock, AT&T and Twitch. You may also find that some small local retailers or certain websites take Bitcoin, but you’ll have to do some digging. That said, PayPal has announced that it will enable cryptocurrency as a funding source for purchases this year, financing purchases by automatically converting crypto holdings to fiat currency for users. “They have 346 million users and they’re connected to 26 million merchants,” says Spencer Montgomery, founder of Uinta Crypto Consulting. “It’s huge.”

What is Secret Chats of Telegram

Secret Chats are one of the service’s additional security features; it allows messages to be sent with client-to-client encryption. This setup means that, unlike regular messages, these secret messages can only be accessed from the device’s that initiated and accepted the chat. Additionally, Telegram notes that secret chats leave no trace on the company’s services and offer a self-destruct timer.

Python Codes from us


Telegram Python Codes
FROM USA