python element in list and element no in list, simple example


element in list

if 2 in [1, 2, 3]:
    print('2 in list')
else:
    print('2 in not list')


if 4 in [1, 2, 3]:
    print('4 in list')
else:
    print('4 in not list')


if (1,2) in [(1, 2) , (3, 2)]:
    print('(1,2) in list')
else:
    print('(1,2) in not list')

result



element no in list
if 4 not in [1, 2, 3]:
    print('4 not in list')
else:
    print('4 in list')


if (1,2) not in [(1, 2), (3, 2)]:
    print('(1,2) in not linst')
else:
    print('(1,2) in list')

result





TensorFlow Basic, print tf.Variable, ^^

All things start from the session

import tensorflow as tf

#define a variable to hold normal random values
normal_rv = tf.Variable( tf.truncated_normal([
10,10],stddev = 0.1))

#initialize the variable
init_op = tf.initialize_all_variables()

#run the graph
with tf.Session() as sess:
    sess.run(init_op) #execute init_op
    #print the random values that we sample
   
print (sess.run(normal_rv)

or

import tensorflow as tf

def create_weights(shape):
    return tf.Variable(tf.truncated_normal(shape, stddev=0.1))

weights = create_weights(shape=[10,10])
init_op = tf.initialize_all_variables()

#run the graph
with tf.Session() as sess:
    sess.run(init_op) #execute init_op
    #print the random values that we sample
    print (sess.run(weights))






Removing duplicates in lists using set, python

Simple example using set


>>> t = [1, 2, 3, 5, 6, 7, 8]
>>> t = t + [1]
>>> t = t + [2]

>>> t = [1, 2, 3, 1, 2, 5, 6, 7, 8]
>>> t
[1, 2, 3, 1, 2, 5, 6, 7, 8]
>>> list(set(t))
[1, 2, 3, 5, 6, 7, 8]
>>> s = [1, 2, 3]
>>> list(set(t) - set(s))
[8, 5, 6, 7]

reference : https://stackoverflow.com/questions/7961363/removing-duplicates-in-lists