mainul098
3/24/2018 - 8:01 AM

Python List Operation

#####Convert A List To A String
# List of Strings to a String
listOfStrings = ['One', 'Two', 'Three']
strOfStrings = ''.join(listOfStrings)

# List Of Integers to a String
listOfNumbers = [1, 2, 3]
strOfNumbers = ''.join(str(n) for n in listOfNumbers)
print(strOfNumbers)


####Convert Lists To A Dictionaries
a = [1, 2, 3, 4, 5]

# Create a list iterator object
i = iter(a)

# Zip and create a dictionary
print(dict(zip(i, i)))

#### Split A Python List Into Evenly Sized Chunks
# Your list `x`
x = [1,2,3,4,5,6,7,8,9]

# Split `x` up in chunks of 3
y = zip(*[iter(x)]*3)

# Use `list()` to print the result of `zip()`
list(y)


#### Sorted by the count of Elements
counter = Counter(tasks)
sorted_tasks = []
for key, value in counter.most_common():
    sorted_tasks.extend([key]* value) 
    
print(sorted_tasks)